I want to be able to use items from database to generate some routes. so if I add new types I don’t have to manually create new routes. I have some lower priority routes so I can’t just use match “:type”, :to => “items#search”. I looked for this and couldn’t find anything on it so I just tried it and it worked.
Type.find(:all).each do |type|
name = type.name
match "#{name}", :to => "items#search"
end
My question is, is it a bad practice to do so, and if it is, why?
Thanks
EDIT:
Even thoough I already accepted an answer, I should probably add that what I was really trying to accomplish is to pass the name of the type as parameter to the route, like so:
Type.find(:all).each do |type|
name = type.name
match "#{name}", :to => "items#search", :type => name
end
It is fine as all the different items using the same routes for item.
So all the rows in a database table called ‘items’ will use the same same of routes.
If you had another model, say ‘price_ranges’ you could have additional routes to access its methods.