简体   繁体   English

在ActiveAdmin中创建搜索页面

[英]Create a search page in ActiveAdmin

I'm using ActiveAdmin to deploy my project. 我正在使用ActiveAdmin部署我的项目。 And I had some problem when I was developing. 而且我在开发时遇到了一些问题。 I had some database table, eg: "Worker", "Product", "Task". 我有一些数据库表,例如:“工人”,“产品”,“任务”。 I wanted to create a page to search on those table with many situation. 我想创建一个页面来搜索有很多情况的那些表。

I created a simple page: 我创建了一个简单的页面:

ActiveAdmin.register_page "my page" do
content do
    panel "Search details" do
        panel "By Name" do
            render :partial => "form"
        end
    end
end 
end

And this is _form.html.erb 这是_form.html.erb

<form action="" method="post">
<input type="text" value="" name="taskid">Task ID</input>
<input type="text" value="" name="productid">Product ID</input>
<input type="text" value="" name="workerid">Worker ID</input>
<input type="submit" value="Submit"/>
</form>

But I don't know how can I call a controller from a form? 但是我不知道如何从表单中调用控制器? (which controller was defined) And How can I render or show the result to the content area of "my_page" in Activeadmin from a controller? (定义了哪个控制器)以及如何从控制器将结果呈现或显示到Activeadmin中“ my_page”的content区域?

Anyone may help me? 有人可以帮助我吗? plz! 请!

Design the form such that it uses the existing active admin filters and displays the results accordingly. 设计表单,使其使用现有的活动管理员过滤器并相应显示结果。 You may want to look at the HTML of your filter forms (using firebug), in order to get the required params, and the submit action. 您可能需要查看过滤器表单的HTML(使用Firebug),以获取所需的参数和Submit操作。 Here is the partial which I use to search my User model (constructed from user filters): 这是我用来搜索用户模型的部分内容(由用户过滤器构成):

<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 User Email</label><br/>
      <input type="text" name="q[email_contains]" id="q_email" />
      <input type="submit" value="Go" name="commit" id="q_submit" />
    </div>
  </form>
</div>

and displays the result in the existing format. 并以现有格式显示结果。 You don't need to design new views for that. 您不需要为此设计新的视图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM