Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use a nested Resource or have a collection on the resource

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?

like image 555
Drazen Avatar asked Dec 20 '22 05:12

Drazen


1 Answers

This is the solution

resources :devices do   
    collection do
      resources :activities, :controller => 'device_activities'
    end
  end
like image 81
Drazen Avatar answered Mar 07 '23 17:03

Drazen