Forum: Ruby on Rails Nested Resources

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
(Guest)
on 2007-07-01 21:22
(Received via mailing list)
I have a user model that can have one album. Album can have multiple
photos. How do I create nested resources for these three models? How
do you avoid nesting more than two levels?

All the examples I have seen only have nesting with two levels. TIA.
Rick O. (Guest)
on 2007-07-01 22:08
(Received via mailing list)
On 7/1/07, removed_email_address@domain.invalid 
<removed_email_address@domain.invalid> wrote:
>
> I have a user model that can have one album. Album can have multiple
> photos. How do I create nested resources for these three models? How
> do you avoid nesting more than two levels?
>
> All the examples I have seen only have nesting with two levels. TIA.

You can nest as deeply as you want.

--
Rick O.
http://lighthouseapp.com
http://weblog.techno-weenie.net
http://mephistoblog.com
(Guest)
on 2007-07-02 07:34
(Received via mailing list)
I have:

map.resources :users do |user|
    user.resource :album do |album|
      album.resources :photos
    end
  end

Should I use the singular resource for my case?Thanks.
Perry S. (Guest)
on 2007-07-02 07:47
removed_email_address@domain.invalid wrote:
> I have:
>
> map.resources :users do |user|
>     user.resource :album do |album|
>       album.resources :photos
>     end
>   end
>
> Should I use the singular resource for my case?Thanks.

From the ri documentation for "resource":

     See map.resources for general conventions. These are the main
     differences:

       - a singular name is given to map.resource.  The default
controller name is taken from the singular name.
       - To specify a custom plural name, use the :plural option.  There
is no :singular option
       - No default index, new, or create routes are created for the
singleton resource controller.
       - When nesting singleton resources, only the singular name is
used as the path prefix (example: 'account/messages/1')
This topic is locked and can not be replied to.