views:

30

answers:

1

Okay so I am working on making a site for my previous boss who runs an animal control business. My index.html.erb consists of code like this:

<div id="bats"><img alt="Big brown bat" src="/images/bigbrown.png" style="position: relative; border: 0.25em outset;" />
<p class="text_center"><%= link_to @animals[0].name, animal_path(@animals[0]) %></p></div>

<div id="squirrel"><img alt="Grey Squirrel" src="/images/grey_squirrel.png" style="position: relative; border: 0.25em outset;" />
<p class="text_center"><%= link_to @animals[1].name, animal_path(@animals[1]) %></p></div>

<div id="flying"><img alt="Flying Squirrel" src="/images/flying-squirrel.png" style="position: relative; border: 0.25em outset;"/>
<p class="text_center"><%= link_to @animals[2].name, animal_path(@animals[2]) %></p></div>

<div id ="groundhog"><img alt="Groundhog" src="/images/groundhog.png" style="position: relative; border: 0.25em outset;" />
<p class="text_center"><%= link_to @animals[3].name, animal_path(@animals[3]) %></p></div>

The pages are mostly static with a lot of text, so I guess my two questions are, should I even have the animals in a database (which just consists of their name)? And if I do keep them in a database, how should I format my show.html.erb which is going to go into greater detail about the animal selected from my index.html.erb page? Use if, else if, etc... or make a page specific to each animal and just redirect there when the animal is selected?

Thanks in advance!

+1  A: 

If I were to redo your example page, I'd add a short_description, long_description, and image_url for each animal in the database and do something like this:

<% @animals.each do |animal| %>
  <div id="animal_<%= animal.id %>"><img alt="<%= animal.short_description %>" src="<%= animal.image_url %>" style="position: relative; border: 0.25em outset;" />
  <p class="text_center"><%= link_to animal.name, animal_path(animal) %></p></div>
<% end %>

to generate it.

The long_description would be to give more detail. If there is enough information to fill a page about each animal, I would use a separate show page.

phaedryx
Yes each animal is going to have enough information for its own page so I think I might just create a page for each, I didn't know you could add an image_url to the database either I may do that as well (I am still relatively new to rails). Thanks for the input
mike
Why create a page for each, when a show.html.erb file, and the corresponding controller action would do this for you? Then it's a matter of using ERB code like phaedryx specified to put info about the animal on the page depending on which animal you've clicked a link for.
davidcelis
That is kind of what I would like to happen but if I just put the description in the database then I will have no html or css control over certain parts of text within the description(i.e. making words bold, underlined, add certain spaces between paragraphs), I could only make the ERB call for the description. I guess with some ruby text processing I could format it how I wanted but I think using html and css would be easier
mike