如何向Active Admin仪表板添加过滤器? [英] How to add a filter to Active Admin dashboard?

查看:77
本文介绍了如何向Active Admin仪表板添加过滤器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Active Admin仪表板页面上为我的几个模型添加搜索功能。我该怎么做?

I want to add search functionality for a couple of my models on the Active Admin Dashboard page. How do I do that?

对于常规模型,我可以使用过滤器来做到这一点,但是如何在仪表板视图上做到这一点。本节和ActiveAdmin :: Dashboards.build中可用的方法是什么?

For a regular model I can do that using "filter", but how do I do that on Dashboard view. What are the methods available within section and ActiveAdmin::Dashboards.build?

推荐答案

添加我的操作方法(遵循Sjors的建议) ),这样其他人可能会发现它有用:

Adding how I did it (following advice from Sjors), so that someone else may find it useful:

在dashboards.rb中:

in dashboards.rb:

  section "Search User", :priority => 4 do
    div do
      render "search_user"
    end
  end

in views / admin / dashboard / _search_user.html.erb(使用Firebug的用户过滤器的复制HTML):

in views/admin/dashboard/_search_user.html.erb (Copied HTML of the user filter using firebug):

<div class="panel_contents">
  <form method="get" id="q_search" class="filter_form" action="/admin/users" accept-charset="UTF-8">
    <div class="filter_form_field filter_string">
      <label for="q_email" class=" label">Search Email:</label>
      <input type="text" name="q[email_contains]" id="q_email" />
      <input type="submit" value="Go" name="commit" id="q_submit" />
    </div>
  </form>
</div>

这篇关于如何向Active Admin仪表板添加过滤器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆