[英]Search form for Paper_trail history using Ransack gem
I'm struggling to get a search form for my active record history. 我正在努力寻找一份我的有效记录历史记录的搜索表。 I'm using the paper_trail gem as well as ransack.
我正在使用paper_trail宝石以及随身行李。 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>
#<#:0x007fede31da910>的未定义方法`paper_trail_versions_path'
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. 您看到的错误来自于
search_form_for
帮手试图猜测您的表单操作的URL。
Under the hood , Ransack uses the polymorphic_path
rails helper, which is, according to the doc , a method 在后台,Ransack使用
polymorphic_path
rails helper, 根据文档 ,这是一种方法
for smart resolution to a named route call when given an Active Record model instance
在给定Active Record模型实例的情况下,智能地解决命名路由调用
In your case, your model is a PaperTrail::Version
, which resolves to paper_trail_versions_path
. 在您的情况下,您的模型是
paper_trail_versions_path
PaperTrail::Version
,它解析为paper_trail_versions_path
。
To fix the error, you can either : 要解决该错误,您可以:
routes.rb
file, so that the helper is defined routes.rb
文件中定义相应的资源,以便定义帮助程序 url
option, with the path to your form's action. url
选项以及表单操作的路径。 Hope it helps! 希望能帮助到你!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.