I’m making a sample library of songs. Table name is ‘Songs’. Columns are
appropriate with Artist, Album etc.
I have a show page for each record which displays information about the
song. I want the list to display in the following format:
:
:
On the show page, I’m printing the Artist Name, Album Name etc. I want
these values (Artist Name, Album Name etc.) to be links. I want these
links to redirect the user to the list page with the appropriate
parameters.
Help?
Pale H. wrote:
I’m making a sample library of songs. Table name is ‘Songs’. Columns are
appropriate with Artist, Album etc.
It sounds from this like you have not normalized your database. I see at
least three models here:
Artist
has_many :albums
has_many :songs, :through => :albums
Album
belongs_to :artist
has_many :songs
Song
belongs_to :album
I have a show page for each record which displays information about the
song. I want the list to display in the following format:
@artist.albums.each do |album|
:
album.songs.each do |song|
end
end
On the show page, I’m printing the Artist Name, Album Name etc. I want
these values (Artist Name, Album Name etc.) to be links. I want these
links to redirect the user to the list page with the appropriate
parameters.
<%= link_to artist.name, artist_path(@artist) %>
<%= link_to album.name, album_path(album) %>
I understand what you’re saying. So there’s no responsible way to do it
from a single table (Songs)?
Pale H. wrote:
I understand what you’re saying. So there’s no responsible way to do it
from a single table (Songs)?
No! The whole point of a properly normalized RDBMS is that you don’t
repeat data. In most cases, it is irresponsible not to normalize at
least up to the Third Normal Form.
Best,
–Â
Marnen Laibow-Koser
http://www.marnen.org
[email protected]
Read more about normal forms and database design here:
http://dev.mysql.com/tech-resources/articles/intro-to-normalization.html
That’s just from the database point-of-view. I haven’t even gotten into
proper Object Oriented Programming (OOP) design principals, and
Model-View-Controller.
I’ll gladly read through. Thanks for your help.
Pale H. wrote:
I understand what you’re saying. So there’s no responsible way to do it
from a single table (Songs)?
In a word, “No.”
You would be breaking just about every rule in the RDBMS book. RDBMS has
a set of rules referred to as normal forms. A single table design in
this case would not comply with what is called the “First Normal Form
(1NF).” The Second Normal (2NF) depends on the database complying to
1NF. Each subsequent normal form continues this dependency.
Read more about normal forms and database design here:
http://dev.mysql.com/tech-resources/articles/intro-to-normalization.html
That’s just from the database point-of-view. I haven’t even gotten into
proper Object Oriented Programming (OOP) design principals, and
Model-View-Controller.