每个循环我都有一个基本的 eRuby
<% @product_images.each do |image|%>
<% if @counter < 4 %>
<% p 'Im in here' %>
<% else %>
<% return %>
<% end %>
<% @counter += 1 %>
<% p @counter %>
<% end %>
在我的循环中,我有一个if
检查 if @counter
is <
than的语句4
。
控制器代码
def show
productId = params[:id]
@product_images = ProductImage.where("product_id = ?", productId)
@counter = 0
end
当我运行此代码时,它应该在计数器大于 4 时返回,但我收到一条错误消息no implicit conversion of nil into String
这是非常简单的代码,我似乎无法弄清楚我做错了什么。好像要断线了
<% if @counter < 4 %>
这是错误的图片: