开发者

Questions on nested resources in Ruby on Rails

开发者 https://www.devze.com 2023-01-04 15:22 出处:网络
How can I specify a custom action for a nested URL in ruby on rails? For example, I have two resources people and book. In the b开发者_如何学运维ook controller, I have a custom action, say foo_action.

How can I specify a custom action for a nested URL in ruby on rails? For example, I have two resources people and book. In the b开发者_如何学运维ook controller, I have a custom action, say foo_action. I am wonder how can I use nested resources in ruby on rails to specify something like:

people/10/book/foo_action/20

basically, call the foo_action associated with book 20 which belongs to people 10. (people and book are one-to-many relations).

Thanks a lot.


map.resources :people do |person|
  person.resources :books, :member => {:foo_action => :get}
end

Replace :get with any method your action should be accessible with (get, post, put or delete).

0

精彩评论

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