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.
E3640176765dae2465d33ef6eb114691?d=identicon&s=25 bcparanj@gmail.com (Guest)
on 2007-07-01 19: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.
821395fe70906c8290df7f18ac4ac6cf?d=identicon&s=25 Rick Olson (Guest)
on 2007-07-01 20:08
(Received via mailing list)
On 7/1/07, bcparanj@gmail.com <bcparanj@gmail.com> 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 Olson
http://lighthouseapp.com
http://weblog.techno-weenie.net
http://mephistoblog.com
E3640176765dae2465d33ef6eb114691?d=identicon&s=25 bcparanj@gmail.com (Guest)
on 2007-07-02 05: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.
3f38541776a2513a20ea2f1c2d522cb3?d=identicon&s=25 Perry Smith (pedz)
on 2007-07-02 05:47
bcparanj@gmail.com 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.