Ruby on Rails image problem

N

Nick

hey, i am new to ruby, and i want to try this out
just showing all the products from the database with there image

this is the code:

<html>
<head>
<title>All Recipes</title>
</head>
<body>

<h1>Catalogus</h1>
<table cellspacing="0" border="0">

<% @products.each do |product| %>
<tr class="productnaam">
<td width="450px" class=""><%= link_to product.name, :action => "show",
:id => product.id %></td>
<td align="right"><%= link_to "<img src='details.gif' />", :action =>
"show", :id => product.id %></td>
</tr>
<tr>
<td><b>Prijs/stuk:</b> ? <%= product.price %></td>
<td align="right">
<img src="<%= product.image %>" alt="<%= product.name %>"
class="catalogus"/>
</td>
</tr>
<% end %>

</table>

<p><%= link_to "Create new recipe", :action => "new" %></p>
<img src="details.gif"/>
</body>
</html>


i cant get the image to show, how must u do that, even an regular image, and
where do i need to put the files????

thanks in advance
 
G

Guilhem.Vellut

You can put all your images inside public/images, which is created by
the rails command, so it alread exists. If you do that, you can use the
helper image_tag to have Rails automatically generate the correct tag.
For example, to display your details.gif, you can do the following :
<%= image_tag "details.gif" %>
And Rails will generate the correct img tag (including when the root of
your Rails application is not the root of your web server), something
like:
<img src="/approot/images/details.gif" alt="DETAILS" />

See
http://api.rubyonrails.com/classes/ActionView/Helpers/AssetTagHelper.html#M000365
for more details.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,591
Members
45,100
Latest member
MelodeeFaj
Top