I'm struggling to get a search form for my active record history. I'm using the paper_trail gem as well as ransack. Both, alone, are working well. But whenever I try to implement a search form I get a strange error:
undefined method `paper_trail_versions_path' for #<#:0x007fede31da910>
This line from my views gets highlighted:
<%= search_form_for @q, html: {class: "input-group"} do |f| %>
Here's the code of the controller:
def history
@all_versions = PaperTrail::Version.order('created_at DESC')
@versions = @all_versions.paginate(:page => params[:page], :per_page => 100)
@q = @versions.search(params[:q])
@versions = @q.result
respond_to do |format|
format.html
end
end
the views:
<%= search_form_for @q, html: {class: "input-group"} do |f| %>
<%= f.search_field :whodunnit_or_item_id_cont, placeholder: "Search for Users or Actions..", class: "form-control" %>
<span class="input-group-btn">
<%= button_tag(type: 'submit', class: "btn btn-default") do %>
<i class="fa fa-search"></i>
<% end %>
</span>
<% end %>
Any Ideas?
Thanks in advance!
EDIT resolved, thanks to answer:
<%= search_form_for @q, html: {class: "input-group"}, :url => "/dashboards/history/" do |f| %>
The error your see comes from the URL the search_form_for
helper tries to guess for your form's action.
Under the hood , Ransack uses the polymorphic_path
rails helper, which is, according to the doc , a method
for smart resolution to a named route call when given an Active Record model instance
In your case, your model is a PaperTrail::Version
, which resolves to paper_trail_versions_path
.
To fix the error, you can either :
routes.rb
file, so that the helper is defined url
option, with the path to your form's action. Hope it helps!
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.