Alan
Alan

Reputation: 62

Rails Link_to image tag isnt retrieving image from database

I'm brand new to rails (and coding in general) so I've a quick question on retrieving images from a database

Running rails 3.2.8

I have a list of products, code, description, price and product_image in the database, The product images is stored as 123.jpg in the database and the image itself is stored in app/assets/images folder

In my view I have the following code

    <div class="center_content">

<div class="center_title_bar">Latest Products</div>

            <% @camera_catalogues.each do |camera_catalogue| %>

    <div class="prod_box">
        <div class="top_prod_box"></div>
        <div class="center_prod_box">            
             <div class="product_title"><a href="details.html"><%= camera_catalogue.model_description %></a></div>
             <div class="product_img"><a href="details.html"><%= link_to (image_tag camera_catalogue.product_image),camera_catalogue %></a></div>
             <div class="prod_price"><span class="reduce">350$</span> <span class="price"><%=number_to_currency(camera_catalogue.price, :unit =>"&euro;")%> </span></div>                        
        </div>
        <div class="bottom_prod_box"></div>             
        <div class="prod_details_tab">
        <a href="#" title="header=[Add to cart] body=[&nbsp;] fade=[on]"><img src="assest/cart.gif" alt="" title="" border="0" class="left_bt" /></a>
        <a href="#" title="header=[Specials] body=[&nbsp;] fade=[on]"><img src="assest/favs.gif" alt="" title="" border="0" class="left_bt" /></a>
        <a href="#" title="header=[Gifts] body=[&nbsp;] fade=[on]"><img src="assets/favorites.gif" alt="" title="" border="0" class="left_bt" /></a>           
        <a href="details.html" class="prod_details">details</a>            
        </div>                     
    </div>

Everything displays correctly except that the image is not retrieved from the database which is this line

    <div class="product_img"><a href="details.html"><%= link_to (image_tag camera_catalogue.product_image),camera_catalogue %></a></div>

Does the image in the database need to be saved with a different url. i.e. instead of 123.jpg it is saved as assets/123.jpg

or is there some other error in my code.

Help/advice greatly appreciated :)

Upvotes: 2

Views: 904

Answers (1)

Paritosh Singh
Paritosh Singh

Reputation: 6384

Use it like this

 <div class="product_img"><%= link_to (image_tag (camera_catalogue.product_image)),camera_catalogue %></div>

I guess it will work for you. You need not use 'assests/image_name'

Upvotes: 1

Related Questions