Working on a CMS, problem with Frontend

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

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 M. [email protected] wrote:

Album
@artist = Artist.find(params[:id])
Posted via http://www.ruby-forum.com/.


Ross R.
www.sorrylies.com

that worked, thanks so much

is there a way to organize them by date? i have a field release_date
that i’d like to organize them by

Ross R. 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 R.
www.sorrylies.com

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 M. [email protected] wrote:

for artist in @artsists
www.sorrylies.com


Posted via http://www.ruby-forum.com/.


Ross R.
www.sorrylies.com

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

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 R. wrote:

Not sure what you mean by that, have you got an example of what you
want to produce?

On 11/19/06, Matt M. [email protected] wrote:


Ross R.
www.sorrylies.com

Not sure what you mean by that, have you got an example of what you
want to produce?

On 11/19/06, Matt M. [email protected] wrote:


Ross R.
www.sorrylies.com

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%>

<%=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 M. [email protected] wrote:

Artist C - Album Name
Artist C - Album Name

On 11/19/06, Matt M. [email protected] wrote:

Posted via http://www.ruby-forum.com/.


Ross R.
www.sorrylies.com

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs