Reputation: 2155
Describing the following scenario:
Is something like this possible? I do not know how to form something like this in routes.rb
Thanks!
Upvotes: 1
Views: 654
Reputation: 6199
Take a look at friendly_id. It doesnt generate routes dynamically but instead it lets u use the name as the ID.
Upvotes: 2
Reputation: 4113
Rails provides method in your models called to_param. This method returns URL for your model instance.
For example: you have model User
user = User.find_by_name('John')
user_path(user) # => /users/1
You can ovverride to_param method to return URL such as:
/users/John
Here you can read more:
http://apidock.com/rails/ActiveRecord/Base/to_param
Upvotes: 1