Reputation: 1
I have a search form that needs to POST to 'users/search'. Following are the relevant code snippets:-
Form
<%=simple_form_for @user, :url => search_user_path(@user), :input_html => {:method => :post} do |f|%>
<div id="top" style="width:979px; height:30px;">
<%= select "search", :area_id, Area.find(:all).collect { |p| [p.name, p.id]}, {:selected => current_user.address.area} %>
<%= f.association :categories, :as => :check_boxes, :label => false%>
<%= f.submit "Submit"%>
</div>
<% end %>
I expect this to POST to users/:id/search
routes.rb
resources :users do
member do
post 'search'
end
end
rake routes | grep search
search_user POST /users/:id/search(.:format) {:action=>"search", :controller=>"users"}
So the route exists
Users controller has the following method
def search
Rails.logger.debug('In users#search')
end
When I hit submit I get a Routing error
Started POST "/users/9/search" for 127.0.0.1 at 2011-10-28 14:11:04 +0530
ActionController::RoutingError (No route matches "/users/9/search"):
I am clueless on this and after a lot of wasted research I am resorting to the community for inputs. Any pointers will be hugely appreciated. Thanks.
FYI I am on rails 3.0.9 and ruby 1.9.2
-Tarun
Upvotes: 0
Views: 1077
Reputation: 8954
You need to write this in plural:
search_users_path(@user)
Also your form is a little bit weired. You could simply write
<%= form_for @user, search_users_path(@user) do |f| %>
Instead of
<%=simple_form_for @user, :url => search_user_path(@user), :input_html => {:method => :post} do |f|%>
You dont need the :method => :post
Upvotes: 1