Given a one to many relationship between a user managed with devise and a “thing”, my goal is to draw restful routes like:
http://host/username
http://host/username/things
http://host/username/things/1
...
I am aware of nested resources in Rails routes, but I can’t figure out how to apply it to a generic User model created and managed via devise.
You can use
scopefor this:Combine this with
to_paramon the user model:And you’ll have routes such as
/username/things. Be careful though, the username shouldn’t contain any dots, forward slashes or standard URI characters. You may want to chuck aparameterizeon the end ofusernameto make sure.