How to give the First image in a gallery a different class than the rest of the images - Carrierwave

Posted by ChrisBedoya on Stack Overflow See other posts from Stack Overflow or by ChrisBedoya
Published on 2013-06-24T22:16:56Z Indexed on 2013/06/24 22:21 UTC
Read the original article Hit count: 228

I have a model called "Photo" that belongs to a model called "Shoe". I using Carrierwave to upload multiple images.

index.html.erb

  <% shoes.each do |shoe| %> 
    <div class="shoe">
      <div class="gallery">
        <% shoe.photos.each do |photo| %>
          <%= link_to image_tag(photo.photo_file.url(:thumb).to_s), photo.photo_file.url.to_s, :class => 'fancybox', :rel => 'gallery' %>
        <% end %>
      </div>
    </div>
  <% end %>

Outputs this:

<div class="shoe">
     <div class="gallery">
        <a class="fancybox" href="../nike-kd-6-meteorology-2.jpg" rel="gallery">
           <img src="../thumb_nike-kd-6-meteorology-2.jpg">
        </a>
        <a class="fancybox" href="../nike-kd-6-meteorology-2.jpg" rel="gallery">
           <img src="../thumb_nike-kd-6-meteorology-2.jpg">
        </a>
        <a class="fancybox" href="../nike-kd-6-meteorology-2.jpg" rel="gallery">
           <img src="../thumb_nike-kd-6-meteorology-2.jpg">
        </a>
     </div>
</div>

But I want the first image of each gallery to be able to have its own class and the rest of the images to have their own class. Something like this:

        <a class="firstclass" href="../nike-kd-6-meteorology-2.jpg" rel="gallery">
           <img src="../thumb_nike-kd-6-meteorology-2.jpg">
        </a>
        <a class="fancybox" href="../nike-kd-6-meteorology-2.jpg" rel="gallery">
           <img src="../thumb_nike-kd-6-meteorology-2.jpg">
        </a>
        <a class="fancybox" href="../nike-kd-6-meteorology-2.jpg" rel="gallery">
           <img src="../thumb_nike-kd-6-meteorology-2.jpg">
        </a>

How can I do this?

Also I want each gallery to have its own unique id but when I try to add this:

:rel => 'gallery<%= shoe.id %>'

I get a Syntax error.

Thanks.

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about carrierwave