Reputation: 264
I've been beating my head against the wall for a little too long. I'm sure I'm missing something obvious, but here goes. I added the following line to my routes.rb file:
get '/:location_or_budget.:format' => 'listings#search_by_location_or_budget', as: :search
When I run 'rake routes', I see this route in the output:
search GET /:location_or_budget.:format listings#search_by_location_or_budget
When I try to use the route in my code like this:
link_to name, search_path(:location_or_budget => 'boston')
I get the following:
ActionController::RoutingError (No route matches {:controller=>"listings", :action=>"search_by_location_or_budget", :location_or_budget=>"boston"}):
I feel like I set everything up correctly. I've verified that the method 'search_by_location_or_budget' exists and is public. Does anyone know what might be wrong or how I might go about troubleshooting this?
Upvotes: 0
Views: 36
Reputation: 30473
It is because you requirest :format part. Try this:
get '/:location_or_budget.:format' => 'listings#search_by_location_or_budget', :as => :search, :defaults => { :format => 'html' }
Or
get '/:location_or_budget(.:format)' => 'listings#search_by_location_or_budget', :as => :search
Upvotes: 1