how do you get the rails image path when you don't want to use an image tag

12,667

Solution 1

You want the path of an image? You might try the aptly named #image_path helper method.

Solution 2

You could use something like this. The helper is marginally useful. Honestly, unless there's some dynamic component, there's nothing wrong with just using HTML

link_to("a","/resources/images/weight1.jpg", :rel=>"lightbox-a", :title=>"Beautiful, isn't it?")

If the image is dynamic, you could always assign a variable with the path to the image (determined how you like)

<a href="<%= @image_path %>" rel="lightbox-a" title="Foo" />a</a>

Solution 3

Well, assuming the images were in your public/images folder, you could achieve that with something like

<%= link_to 'a', image_path('weight1.jpg'), :rel => 'lightbox-a', :title => 'some title' %>
Share:
12,667
Daniel
Author by

Daniel

Updated on June 13, 2022

Comments

  • Daniel
    Daniel almost 2 years

    I'm using slimbox2 with rails. To make it work you include some markup as follows:

    <a href="resources/images/weight1.jpg" rel="lightbox-a" title="Beautiful, isn't it?">a</a> 
    
    <a href="resources/images/example.jpg" rel="lightbox-a" title="Beautiful, isn't it?">a</a>
    

    So I'm wondering, how do you grab the location of the image to place in the href? Relative addressing? Is their a helper that is useful in this situation?