Weird Data Tags In Rails

Rails Wrapping Image Tags and Wierd Data Tags


Wrapping `image_tag` inside of a `link_to` tag:

      <a href="images/project1.jpg" class="cbp-lightbox" ><i class="fa fa-search"></i></a>

      <%= link_to 'project1.jpg', class: 'cbp-lightbox' do %>
         <i class="fa fa-search"></i>
      <% end %>

 

Weird Data Tags


Sometimes links have or tags have odd data tags that need to be generated within `image_tag` or `link_to` tags. As noted in this stackoverflow question http://stackoverflow.com/questions/15066830/adding-custom-data-attributes-rails-image-tag something like data-title or data-description does not easily fit in as a parameter like class. 


      <a href="images/project1.jpg" class="cbp-lightbox" data-title="Our Project 1"><i class="fa fa-search"></i></a>

      <%= link_to 'project1.jpg', class: 'cbp-lightbox', :data => { :title => 'Our Project 1' } do %>
         <i class="fa fa-search"></i>
      <% end %>

Putting it all together

 

Combining the two situations makes for an interesting situation. As seen here we need to wrap a link to an image in a special tag. The CSS will make that link to the image not open as a direct link but as a magnified popover in the window. 

    <a href="images/project1.jpg" class="cbp-lightbox" data-title="Our Project 1"><i class="fa fa-search"></i></a>

    <%= link_to 'project1.jpg', class: 'cbp-lightbox', :data => { :title => 'Our Project 1' } do %>
        <i class="fa fa-search"></i>
    <% end %>


Home Office

Cherry Hill, NJ

North New Jersey Office

Hasbrouck Heights, NJ

Philadelphia Office

Media, PA

office Hours

Mon - Fri : 8am to 6pm

Social Media