开发者

show.html.erb format help

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开发者_StackOverflow中文版 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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜