开发者

how to define rails 3.1 custom routes

I want to route http://localhost:3000/users/1/rename/alex to my users controller with rename action.

what I did was:

match 'users/:id/rename/:name' => 'users#rename', but this is not working, the part after 'users/:id/' is not mapped at all, since I cannot get name by params[:name]

Update: In routes.rb

resources :users do
  put 'rename/:code', :action => :rename, :code => /\w{5}/, :on => :member
end

and,

$ rake rou开发者_C百科tes
...
PUT /users/:id/rename/:code(.:format) {:code=>/\w{5}/, :action=>"rename", :controller=>"users"}
...


If you have resources :users, put your match line before it.

Alternatively, you can pass a block to resources:

resources :users do
  match 'rename/:name' => 'users#rename', :on => :member
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜