I’m getting a “No route matches” error when calling search_path in my search_field_tag. The search form is in my header, the idea is simply to be able to do searches on events.
Here is the route in routes.rb:
match '/events/search/:query' => 'events#search', :as => "search"
Here is the code for the search form.
<%= form_tag search_path, :method => :get do %>
<%= text_field_tag :query, params[:query] %>
<%= submit_tag "search", :name => :nil %>
<% end %>
(How to make sure when I submit this form that it will submit to /events/search/:query? :query being the value in the search_field_tag)
Here is the code in my events_controller
def search
@search_q = params[:query]
@events = Event.search @search_q #uses thinking sphinx
respond_with @events
end
I also have created /views/events/search.html.erb
I’m pretty sure the error is coming from the line in the search form where I say search_path. Everything else seems to work exactly as I expect it to, though, for example, if I visit /events/search/someterm it works exactly as I expect it to. It’s just a matter of plugging in the search form and submitting to events#search. Any help? Thanks!
I think the issue here is that query is being passed as a post request. Your route is looking for:
where as you defined:
So just drop the /:query at the end of your route. The query is passed as params on post. No need to have it in the routes.