Domanda

I have been looking for some answer without success. This is for a gallery in Rails using least.js. I need to pass the data-caption as a param to the big image thats going to be the target of the link. It isn't working the way I put the code.

Second I'm trying to give to the link a title but it doesn't work either. What am I doing wrong?

This is my code in the view:

<%= link_to(image_tag("webprojects/thumb/boltexinertial_port_thumb.png", :alt => "Boltex Inertial Website"), image_path( "webprojects/boltexinertial_port.png", :"data-caption" => "Boltex Inertial Website", :title => "Boltex Inertial Website")) %>

This is what the source of the thumbnail results (there is no title):

<a class="active" href="/assets/webprojects/boltexinertial_port.png">

    <img title="Boltex Inertial Website" src="/assets/webprojects/thumb/boltexinertial_port_thumb.png" alt="Boltex Inertial Website"></img>

</a>

This is what the source of the big image results (there is no data-caption):

<img src="/assets/webprojects/boltexinertial_port.png"></img>
È stato utile?

Soluzione

to get the html you did provide in comment:

<%= link_to image_path('webprojects/BIG_IMAGE.PNG'), title: "tITLE O THE IMAGE", data: { caption: "<strong>Lorem   ipsum dolor</strong> sit amet, consetetur sadipscing"} do %>
  <%= image_tag 'media/thumbnails/THUMBNAIL.PNG', alt: 'Alt Image Text' %>
<% end %>

Notice you should put your pictures in the assets folder to get it working.

Altri suggerimenti

The parameters data-caption and title should not belong to image_path. I think you can't pass params to image_path. Try with this (also the block version of link_to is more readable in this case):

<%= link_to "#{image_path('webprojects/boltexinertial_port.png')}?data-caption=#{'Boltex Inertial Website'.to_query}", :title => "Boltex Inertial Website" do %>
  <%= image_tag("webprojects/thumb/boltexinertial_port_thumb.png", :alt => "Boltex Inertial Website") %>
<% end %>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top