我有这个静态代码:
%a#carousel-selector-0.thumbnail
%img{:src => "http://placehold.it/170x100&text=one"}/
%li.span2
%a#carousel-selector-1.thumbnail
%img{:src => "http://placehold.it/170x100&text=two"}/
%li.span2
%a#carousel-selector-2.thumbnail
%img{:src => "http://placehold.it/170x100&text=three"}/
%li.span2
%a#carousel-selector-3.thumbnail
%img{:src => "http://placehold.it/170x100&text=four"}/
%li.span2
%a#carousel-selector-4.thumbnail
%img{:src => "http://placehold.it/170x100&text=five"}/
%li.span2
%a#carousel-selector-5.thumbnail
%img{:src => "http://placehold.it/170x100&text=six"}/
这是我的每个循环,使其从db
动态化- @house.attachments.each do |a|
= link_to(image_tag(a.file.url), :id => "carousel-selector-{number}", :class => "thumbnail")
如何使{number}增量?就像在静态例子中一样?
答案 0 :(得分:5)
试试这个:
- @house.attachments.each_with_index do |a,i|
= link_to(image_tag(a.file.url), :id => "carousel-selector-#{i}", :class => "thumbnail")