Daniel
Daniel

Reputation: 16226

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

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?

Upvotes: 2

Views: 12685

Answers (3)

Callmeed
Callmeed

Reputation: 5002

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' %>

Upvotes: 1

BJ Clark
BJ Clark

Reputation: 3275

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

Upvotes: 12

Scott
Scott

Reputation: 654

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>

Upvotes: 1

Related Questions