Nested Resources

How to make photo as a nested resource to album, where

class Album < ActiveRecord::Base           has_many :photos end

class Photo < ActiveRecord::Base          belongs_to : album end

Such that when I perform a show action an albums, I should be able to view only the photos associated with it and not all the photos of the table

When you perform a show action on albums, the url will be something similar to "/albums/<album-id>"

Then in the show method,

def show    @album = Album.find(id)    @photos = @album.photos

   render template to display @photos end

this will display photos of a particular album alone.

Unnikrishnan Kp wrote:

When you perform a show action on albums, the url will be something similar to "/albums/<album-id>"

Then in the show method,

def show    @album = Album.find(id)    @photos = @album.photos

   render template to display @photos end

this will display photos of a particular album alone.

On Jul 12, 11:14 am, Advait Bellur <rails-mailing-l...@andreas-s.net>

I tried the above code and <%=h @employees.find(:all) %> in my show.rhtml file and then when I perform the show action it is displaying " # ".

Can you let me know where am I going wrong

I tried the above code and <%=h @employees.find(:all) %> in my show.rhtml file and then when I perform the show action it is displaying " # ".

Can you let me know where am I going wrong

  Sorry its <%=h @photos.find(:all) %> , I have written it as employee

Hi Advait,

It looks like you're displaying an array. You might want to do something more like this:

<ul>   <% @photos.each do |current_photo| %>     <li>Photo name: <%= current_photo.name %></li>   <% end %> </ul>

gsterndale wrote:

Hi Advait,

It looks like you're displaying an array. You might want to do something more like this:

<ul>   <% @photos.each do |current_photo| %>     <li>Photo name: <%= current_photo.name %></li>   <% end %> </ul>

On Jul 12, 1:56 pm, Advait Bellur <rails-mailing-l...@andreas-s.net>

Thank You very much........Now every thing working wonderfully