开发者

how to define rails 3.1 custom routes

开发者 https://www.devze.com 2023-04-12 18:53 出处:网络
I want to route http://localhost:3000/users/1/rename/alex to my users controller with rename action. what I did was:

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

精彩评论

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

关注公众号