简体   繁体   中英

Create a search page in ActiveAdmin

I'm using ActiveAdmin to deploy my project. 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 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?

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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