Reputation: 2843
I have this code in my routes.rb
shops = Shop.all
shops.each do |shop|
match "/#{shop.url}" => 'shops#show', :id => shop.id
end
So url can be like http: //site/url & not like http: //site/shops/1
& It does work, but I have to restart server after adding a new shop.
Maybe, there is a way to do this stuff without restarting? Or, some other way around?
Thank you
Upvotes: 1
Views: 481
Reputation: 13181
This is an old rails cast, but you'll find elements of answer there
http://railscasts.com/episodes/63-model-name-in-url
As a general advise: you won't need do this kind of loop in your routes, study the tools made available by rails routing and use them
http://guides.rubyonrails.org/routing.html
Upvotes: 1