How to give the First image in a gallery a different class than the rest of the images - Carrierwave
- by ChrisBedoya
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.