Reputation: 15139
I'm trying to create some nice links over my website. I'm creating a search via tags just now, and I wonder if it is possible to create some nice routes like this:
http://myapp.com/search/a_very
http://myapp.com/search/nice_set
http://myapp.com/search/of_tags
or at least like this:
http://myapp.com/articles/search/a_very
http://myapp.com/articles/search/nice_set
http://myapp.com/articles/search/of_tags
I've done some experiments with a link_for, and figured out that it's impossible to avoid action?parameter=value construction there. I'm also trying to avoid any of 'numbers stuff' in the address, like sending ids between actions, etc.. Anyway, I'm just a beginner and I have absolutely no idea which direction should I digg for.
Should it be some routes magic? How to apply that magic to my example? Am I broking 'convention of configuration' paradigm?
Upvotes: 0
Views: 7352
Reputation:
Rails 3 has an updated syntax.
match 'search/:tags' => 'tags#search' :as => 'tag_search'
Upvotes: 6
Reputation: 15302
This shouldn't require much "magic"; it's a pretty standard kind of route. You could do it like this (in routes.rb)
map.tag_search "search/:tags", :controller => "tags", :action => "search"
The above assumes you have a Tags controller with a search action. Inside that action, the end of your URL will be available in params[:tags].
I'd recommend reading the Rails Guide on Routing - it covers this scenario and many others.
Upvotes: 6