I am having some problems with the new routing in Rails 3. What is the best way to prefix the path with开发者_如何学Go a user name. Right now I have the following code:
resources :links, :path => '/:username' do
put 'star', :on => :member
end
But it leaves params empty.
EDIT:
I would like to have a urls like:
/:username/links
/:username/links/:id/star
And I would like to be able to fetch params[:username]
You can use scope
for this, it's much neater:
scope :path => ":username" do
resources :links do
put 'star', :on => :member
end
end
you should user nested resources
resources :users do
resources :links do
put 'star', :on=>:member
end
end
then, if you implement to_param in user.rb
def to_param
username.parameterize
end
Then you'll have
/:username/links
/:username/links/23
/:username/links/23/star
精彩评论