advait
1
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
advait
2
When you perform a show action on albums, the url will be something
similar to “/albums/”
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 B. [email protected]
advait
3
Unnikrishnan Kp wrote:
When you perform a show action on albums, the url will be something
similar to “/albums/”
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 B. [email protected]
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
advait
4
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
advait
5
Hi Advait,
It looks like you’re displaying an array. You might want to do
something more like this:
<% @photos.each do |current_photo| %>
- Photo name: <%= current_photo.name %>
<% end %>
On Jul 12, 1:56 pm, Advait B. [email protected]
advait
6
gsterndale wrote:
Hi Advait,
It looks like you’re displaying an array. You might want to do
something more like this:
<% @photos.each do |current_photo| %>
- Photo name: <%= current_photo.name %>
<% end %>
On Jul 12, 1:56 pm, Advait B. [email protected]
Thank You very much…Now every thing working wonderfully