Ruby on rails form_标签未正确发送
我正在尝试让表单标记在rails 3中工作,但我一直遇到路由错误: 没有路由匹配{:action=>“search”,:controller=>“posts”} 以下是for_标记的代码:Ruby on rails form_标签未正确发送,ruby-on-rails,ruby,form-for,Ruby On Rails,Ruby,Form For,我正在尝试让表单标记在rails 3中工作,但我一直遇到路由错误: 没有路由匹配{:action=>“search”,:controller=>“posts”} 以下是for_标记的代码: <%= form_tag search_post_path, method: :get do %> <br /> <fieldset> <legend>Search</legend> <%= text_
<%= form_tag search_post_path, method: :get do %>
<br />
<fieldset>
<legend>Search</legend>
<%= text_field_tag :search, params[:search], :id => 'search_field' %>
<%= submit_tag "Search", :name => nil %>
<%= link_to_function "Clear", "$('search_field').clear()" %>
</fieldset>
<br />
<% end %>
我觉得我已经尝试了我的路由文件中的所有内容,但没有任何效果。有一次,我得到了要显示的for_,但当我点击提交按钮时,我得到了“search”方法的NoMethodError。您路由的“search”在一个成员上,因此匹配的URL是/posts/:id/search。
但是,您没有提供ID,因此会出现错误。
您应该将搜索路径放在集合块中,如下所示:
resources :posts do
collection do
get 'search'
end
end
所以匹配的URL将是/posts/search。我试过了,但我得到了一个命名错误:未定义的方法'search'哦,是的,它应该是search\u posts\u path,而不是search\u post\u path。
resources :posts do
collection do
get 'search'
end
end