Search code examples
ruby-on-rails-4concatenation

Rails helpers, concatenation


The problem is the following meaning to use a container which I give a background image and I also intend it to be a link to the project (for I am making a portfolio).

<% if project.has_photo? %>
    <div class="img_container" style="background-image:(/photo_store/<%=project.id%>.<%=project.extension%>);,link_to "http://www.asite.com/"></div>
<%else%>
    <p> there's nothing here #<%=project.id%></p>
<%end%>

This doesn't gives any errors however, it doesn't reach the image as you can see, I set and if so it tells me if there is no image, but it does seem to have an image, so I don't really know what's holding it back from displaying it?


Solution

  • Try:

    <% if project.has_photo? %>
       <%= link_to("example_url") do %>
           <div class="img_container" style="background-image: url(/photo_store/<%=project.id%>.<%=project.extension%>)"></div>
       <% end %>
    <%else%>
        <p> theres nothing here </p>
    <%end%>