我已經添加了一個方法到我的控制器並正確路由,但是當我嘗試從form_tag
調用它時,它給我一個路由器錯誤。這是怎麼回事?form_tag不按預期方式工作
<% form_tag search_item_path, :method => 'get' do %>
<%= text_field_tag :name , '' %>
<%= submit_tag "Submit" %>
<% end %>
路線:
resources :items do
collection do
get :search, :as => :search
end
end
耙路線也行:
search_item GET /items/:id/search(.:format) {:action=>"search", :controller=>"items"}
items GET /items(.:format) {:action=>"index", :controller=>"items"}
POST /items(.:format) {:action=>"create", :controller=>"items"}
new_item GET /items/new(.:format) {:action=>"new", :controller=>"items"}
edit_item GET /items/:id/edit(.:format) {:action=>"edit", :controller=>"items"}
item GET /items/:id(.:format) {:action=>"show", :controller=>"items"}
PUT /items/:id(.:format) {:action=>"update", :controller=>"items"}
DELETE /items/:id(.:format) {:action=>"destroy", :controller=>"items
不過,如果我寫的東西是這樣工作的:
<% form_tag url_for(:controller => "items" , :action => "search"), :method => "get" do %>
缺少什麼我在這裏?
我確實刪除了'as =>:search',是的,它是一個複數名稱'search_items_path'。我試過'search_item_path'這就是爲什麼第一次不工作。謝謝。 –