我希望每个循环的第一个元素都是“活动的”并用活动的css类包装它。我尝试了这个,但现在每个项目都是活跃的。我做错了什么?
#myCarousel.carousel.slide
.carousel-inner
- @cities.each do |city|
- city.activities.find_all_by_homepage_city(true).each do |b|
- b.attachments.each_with_index do |a, index|
- if index=0
.active.item
= link_to(image_tag(a.file.url, :height =>"325px", :width =>"650px"))
.carousel-caption
%h4 yep 1
- else
.item
= link_to(image_tag(a.file.url, :height =>"325px", :width =>"650px"))
.carousel-caption
%h4 yep 2
Thanks..remco
答案 0 :(得分:4)
您输错了,if index == 0
不是if index = 0
无论如何,如果我想做你正在做的事情,我会做以下
#myCarousel.carousel.slide
.carousel-inner
- @cities.each do |city|
- city.activities.find_all_by_homepage_city(true).each do |b|
- b.attachments.each_with_index do |a, index|
%div{ :class => "#{index == 0? 'active item' : 'item'}" }
= link_to(image_tag(a.file.url, :height =>"325px", :width =>"650px"))
.carousel-caption
%h4
= index == 0 ? 'yep 1' : 'yep 2'