# Array

**URL:** <https://www.ruby-forum.com/t/array/180063>\
**Category:** Rails\
**Created:** [December 10, 2009, 4:17pm UTC](https://www.ruby-forum.com/t/array/180063 "2009-12-10T16:17:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mercurius](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c89c15/32.png) [@mercurius](https://www.ruby-forum.com/u/mercurius)\
**Post date:** [December 10, 2009, 4:17pm UTC](https://www.ruby-forum.com/t/array/180063/1 "2009-12-10T16:17:27Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![mercurius](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c89c15/32.png) [@mercurius](https://www.ruby-forum.com/u/mercurius)\
**Post date:** [December 10, 2009, 4:32pm UTC](https://www.ruby-forum.com/t/array/180063/2 "2009-12-10T16:32:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mercurius](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c89c15/32.png) [@mercurius](https://www.ruby-forum.com/u/mercurius)\
**Post date:** [December 10, 2009, 5:55pm UTC](https://www.ruby-forum.com/t/array/180063/3 "2009-12-10T17:55:43Z")

</div>

I understand what you’re saying. So there’s no responsible way to do it  
from a single table (Songs)?

---

<div class="post-metadata">

**Author:** ![mercurius](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c89c15/32.png) [@mercurius](https://www.ruby-forum.com/u/mercurius)\
**Post date:** [December 10, 2009, 6:24pm UTC](https://www.ruby-forum.com/t/array/180063/4 "2009-12-10T18:24:31Z")

</div>

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](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![mercurius](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c89c15/32.png) [@mercurius](https://www.ruby-forum.com/u/mercurius)\
**Post date:** [December 11, 2009, 10:36am UTC](https://www.ruby-forum.com/t/array/180063/5 "2009-12-11T10:36:30Z")

</div>

> Read more about normal forms and database design here:  
> [http://dev.mysql.com/tech-resources/articles/intro-to-normalization.html](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.

---

<div class="post-metadata">

**Author:** ![mercurius](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c89c15/32.png) [@mercurius](https://www.ruby-forum.com/u/mercurius)\
**Post date:** [December 10, 2009, 6:28pm UTC](https://www.ruby-forum.com/t/array/180063/6 "2009-12-10T18:28:29Z")

</div>

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](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.
