So I''m working on a CMS to help record labels manage artists, albums, and shows So at the moment I have Artist has_many :albums has_many :shows Album belongs_to :artist Show belongs_to :artist What I''m trying to do is create an action on the front end that will allow me to list all the Artist names (in the database it''s called artist), then under each artist name list all their shows and albums. I''ve been able to do this for individual pages with actions def showartist @artist = Artist.find(params[:id]) end so the address is /showartist/1 for example, then it will list the artist with ID 1, and the album and show with artist_id 1. How could I include them all on one page? thanks, Matt -- 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 -~----------~----~----~----~------~----~------~--~---
in the controller: @artists = Artist.find(:all) in the view: for artist in @artsists for album in artist.albums ...... end for show in artist.shows ..... end end On 11/18/06, Matt Mcinerney <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > So I''m working on a CMS to help record labels manage artists, albums, > and shows > > So at the moment I have > > Artist > has_many :albums > has_many :shows > > Album > belongs_to :artist > Show > belongs_to :artist > > > What I''m trying to do is create an action on the front end that will > allow me to list all the Artist names (in the database it''s called > artist), then under each artist name list all their shows and albums. > I''ve been able to do this for individual pages with actions > def showartist > @artist = Artist.find(params[:id]) > end > > so the address is /showartist/1 for example, then it will list the > artist with ID 1, and the album and show with artist_id 1. > How could I include them all on one page? > > thanks, > Matt > > -- > Posted via http://www.ruby-forum.com/. > > > >-- Ross Riley www.sorrylies.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 -~----------~----~----~----~------~----~------~--~---
that worked, thanks so much -- 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 -~----------~----~----~----~------~----~------~--~---
is there a way to organize them by date? i have a field release_date that i''d like to organize them by Ross Riley wrote:> in the controller: > @artists = Artist.find(:all) > > in the view: > > for artist in @artsists > for album in artist.albums > ...... > end > for show in artist.shows > ..... > end > end > > -- > Ross Riley > www.sorrylies.com-- 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 -~----------~----~----~----~------~----~------~--~---
Yes sure, you can pass in conditions to associated models. Try changing the line above to...... for album in artist.albums.find(:all, :order=>"release_date ASC") or for album in artist.albums.find(:all, :order=>"release_date DESC") depending on which order they need to be in, On 11/18/06, Matt Mcinerney <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > is there a way to organize them by date? i have a field release_date > that i''d like to organize them by > > Ross Riley wrote: > > in the controller: > > @artists = Artist.find(:all) > > > > in the view: > > > > for artist in @artsists > > for album in artist.albums > > ...... > > end > > for show in artist.shows > > ..... > > end > > end > > > > -- > > Ross Riley > > www.sorrylies.com > > > -- > Posted via http://www.ruby-forum.com/. > > > >-- Ross Riley www.sorrylies.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 -~----------~----~----~----~------~----~------~--~---
could i do that somehow in the for artist tag? like for artist in artist.albums.find(:all, :order=>"release_date ASC") so that it organized all the entries by release date, and shows the artist, but ignores their organizational structure -- 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 -~----------~----~----~----~------~----~------~--~---
Not sure what you mean by that, have you got an example of what you want to produce? On 11/19/06, Matt Mcinerney <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > could i do that somehow in the for artist tag? > > like for artist in artist.albums.find(:all, :order=>"release_date ASC") > > so that it organized all the entries by release date, and shows the > artist, but ignores their organizational structure > > -- > Posted via http://www.ruby-forum.com/. > > > >-- Ross Riley www.sorrylies.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 want it to be like Nov 1st Artist A - Album Name Nov 2nd Artist B - Album Name Nov 3rd Artist A - Album Name Nov 4th Artist C - Album Name rather than Nov 1st Artist A - Album Name Nov 3rd Artist A - Album Name Nov 2nd Artist B - Album Name Nov 4th Artist C - Album Name because as it is, it first organizes by artist, then organizes by release date under the artist Ross Riley wrote:> Not sure what you mean by that, have you got an example of what you > want to produce? > > > On 11/19/06, Matt Mcinerney <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >> >> > >> > > > -- > Ross Riley > www.sorrylies.com-- 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 -~----------~----~----~----~------~----~------~--~---
Ok yes. So what you need to do is loop through the albums... Controller: @albums = Album.find(:all, :order=>"release_date ASC") View: <%for album in @albums%> <%=album.release_date%><br /> <%=album.artist.name%> - <%=album.name%> <%end%> As you can see because an album belongs to an artist you can access this object with album.artist and then access any attribute within artist - i''ve guessed at name (album.artist.name) Ross On 11/19/06, Matt Mcinerney <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > I want it to be like > > Nov 1st > Artist A - Album Name > Nov 2nd > Artist B - Album Name > Nov 3rd > Artist A - Album Name > Nov 4th > Artist C - Album Name > > rather than > > Nov 1st > Artist A - Album Name > Nov 3rd > Artist A - Album Name > Nov 2nd > Artist B - Album Name > Nov 4th > Artist C - Album Name > > because as it is, it first organizes by artist, then organizes by > release date under the artist > > > Ross Riley wrote: > > Not sure what you mean by that, have you got an example of what you > > want to produce? > > > > > > On 11/19/06, Matt Mcinerney <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > >> > >> > > >> > > > > > > -- > > Ross Riley > > www.sorrylies.com > > > -- > Posted via http://www.ruby-forum.com/. > > > >-- Ross Riley www.sorrylies.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 -~----------~----~----~----~------~----~------~--~---