i have a field release_date under the table album that belongs_to: artist and i now have a page that outputs: release_date artist - album how can i organize them by that release date? here''s my code at the moment <% for artist in @artists %> <% for album in artist.albums %> <%= album.release_date %><br /> <%= artist.artist %> - <%= album.album %> - <%= link_to ''View Reviews'', :action => ''showalbum'', :id => album %><br /> <% end %> <% end %> -- 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 -~----------~----~----~----~------~----~------~--~---
On 11/18/06, Matt Mcinerney <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > i have a field release_date under the table album that belongs_to: > artist > > and i now have a page that outputs: > release_date > artist - album > > how can i organize them by that release date? > > here''s my code at the moment > > <% for artist in @artists %> > > <% for album in artist.albums %> > <%= album.release_date %><br /> > <%= artist.artist %> - <%= album.album %> - <%= link_to ''View Reviews'', > :action => ''showalbum'', :id => album %><br /> > <% end %> > > <% end %> > > -- > Posted via http://www.ruby-forum.com/. > > > >Matt, You could do a sort like this: <% for album in artist.albums.sort_by{ |a| a.release_date } %> or better yet look at adjusting your has_many call to: has_many :albums, :order => ''release_date'' Hope this helps. -- Zack Chandler http://depixelate.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 works for sorting just the albums, but it sorts the artists alphabetically, then it sorts the releases under that. could i get it to sort everything by release, ignoring the alphabetical artist sorting, so something i could put in <% for artist in @artists %> Zack Chandler wrote:> On 11/18/06, Matt Mcinerney <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >> here''s my code at the moment >> >> -- >> Posted via http://www.ruby-forum.com/. >> >> > >> > > Matt, > > You could do a sort like this: > > <% for album in artist.albums.sort_by{ |a| a.release_date } %> > > or better yet look at adjusting your has_many call to: > > has_many :albums, :order => ''release_date'' > > Hope this helps. > > -- > Zack Chandler > http://depixelate.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 -~----------~----~----~----~------~----~------~--~---
On 11/18/06, Matt Mcinerney <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > that works for sorting just the albums, but it sorts the artists > alphabetically, then it sorts the releases under that. could i get it to > sort everything by release, ignoring the alphabetical artist sorting, so > something i could put in <% for artist in @artists %> > > Zack Chandler wrote: > > On 11/18/06, Matt Mcinerney <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > >> here''s my code at the moment > >> > >> -- > >> Posted via http://www.ruby-forum.com/. > >> > >> > > >> > > > > Matt, > > > > You could do a sort like this: > > > > <% for album in artist.albums.sort_by{ |a| a.release_date } %> > > > > or better yet look at adjusting your has_many call to: > > > > has_many :albums, :order => ''release_date'' > > > > Hope this helps. > > > > -- > > Zack Chandler > > http://depixelate.com > > > -- > Posted via http://www.ruby-forum.com/. > > > >Matt, I don''t understand exactly what you want here... if we have two artists with release dates like this: Artist 1 has albums with release_dates of 1/1/06, 3/1/06, 5/1/06 Artist 2 has albums with release_dates of 2/1/06, 4/1/06 then <% for artist in @artists %> won''t work because they have releases that stagger. What you want to do if the primary sort is release date is something like the following: @albums = Album.find(:all, :include => :artist, :order => ''release_date'') then <% for album in @albums -%> <%= album.release_date.strftime(...) %> - <%= album.artist.name %> <% end -%> Does that make sense? -- Zack Chandler http://depixelate.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 -~----------~----~----~----~------~----~------~--~---