[英]Rails cycle helper function isn't working
I use the cycle helper function inside a loop to cycle between two CSS classes but it doesn't work. 我在循环中使用循环辅助函数在两个CSS类之间循环,但它不起作用。 It always chooses the first CSS class in each iteration. 它总是在每次迭代中选择第一个CSS类。
<% @projects.each do |project| %>
<div class="row">
<div class="<%= cycle("left-animate", "right-animate") + ' col-sm-6' %>"><%= image_tag project.screen_shot %></div>
<div class="col-md-1 hidden-sm"></div>
<div class="<%= cycle("right-animate", "left-animate") + ' col-sm-6 col-md-5' %>">
<h4><%= project.title %></h4>
<%= raw project.description %>
</div>
</div>
<% end %>
Rails version is 5.2 and Ruby version is 2.5.1 Rails版本为5.2,Ruby版本为2.5.1
Missing "name" parameter. 缺少“名称”参数。 Can you use it like this? 你能这样用吗?
<% @projects.each do |project| %>
<div class="row">
<div class="<%= cycle("left-animate", "right-animate, name:'image') + ' col-sm-6' %>"><%= image_tag project.screen_shot %></div>
<div class="col-md-1 hidden-sm"></div>
<div class="<%= cycle("right-animate", "left-animate",name:'summary') + ' col-sm-6 col-md-5' %>">
<h4><%= project.title %></h4>
<%= raw project.description %>
</div>
</div>
<% end %>
You're defining two cycles with the same [implicit] name, so they're cancelling each other out. 您使用相同的[隐含]名称定义了两个循环,因此它们相互抵消。
It sounds like you might want to use current_cycle
in the second instance, to re-use the value from the preceding call. 听起来你可能想在第二个实例中使用current_cycle
来重用前一个调用中的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.