'clean way to read out id in a request path in ruby on rails

I have a request that comes in like this: api/v1/photos/1/media/2

"1" and "2" are ids I need to read out in the controller. "2" I can get through the parameters: params["id"].

What's a clean way to read out the first id "1"? I can get the entire path with request.path or request.url. But since this returns a string I would have to do some string manipulation to get to the id. Is there a better/cleaner way to do this?

The routes are defined so:

resources :photos do
  member do
    resources :media
      member do
      end 
  end
end

i tried printing out params but it only had the second id and the action.



Solution 1:[1]

Have you tried what params return if routes are like this?

resources :photos do
   resources :media
end

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 kouroubel