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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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 > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> 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 wrongSorry its <%=h @photos.find(:all) %> , I have written it as employee -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > 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 > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>Thank You very much........Now every thing working wonderfully -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---