Reputation: 24754
I use nested resources
#route.rb
resources :users do
resources :posts
end
and with
#route.rb
match '/:username' => 'users#show', :as => :user
I change /user/id
to /username
but, how change /users/username/posts
to username/posts
?
Upvotes: 1
Views: 246
Reputation: 24754
this work with
#route.rb
match '/:username/posts' => 'posts#index', :as => :user_posts
Upvotes: 0
Reputation: 9756
:id is really just a reference to they key that will be used to find your object. It doesn't necessarily need to be the integer representation.
Take a look at the friendly_id gem to see how slug handling is done and how to tell ActiveRecord to use that instead of the integer it expects by default.
Upvotes: 1