4

I have 2 Models, 'Device' and 'DeviceActivity' where Device has many Device Activities. Now if i would use regular resource nesting i would end up with something like

/devices/1/activities

or

/devices/1/activities/1

What i want is to access

/devices/activities

where i want to show all activities of all devices, like an activity stream. Is creating a collection on the Devices resource the right way?

4

2 回答 2

11

这是解决方案

resources :devices do   
    collection do
      resources :activities, :controller => 'device_activities'
    end
  end
于 2013-05-29T00:42:05.910 回答
0

所以你想要一个 GET /devices/activities 就我阅读资源丰富的路由而言,这没有被涵盖,但你可以在路由中自己定义这个路由,比如

match "devices/activities" => 'devices#activities',    :as => :devices_activities

所以你只需要在你的 DevicesController 中分别用视图实现活动方法

于 2013-05-28T23:57:08.947 回答