1

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 ?

JuanPablo
  • 23,792
  • 39
  • 118
  • 164
  • This is such a common requirement I think it's about time Rails made this possible. There's no reason it has to force `:id` everywhere... this could be configured without complicating the code for 99% of cases. Unfortunately I doubt you'll get the answer you're looking for ;) – d11wtq Jul 11 '11 at 00:35

2 Answers2

1

: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.

Matt Polito
  • 9,588
  • 2
  • 19
  • 13
0

this work with

#route.rb
match '/:username/posts' => 'posts#index', :as => :user_posts
JuanPablo
  • 23,792
  • 39
  • 118
  • 164