I have a basic eRuby each loop
<% @product_images.each do |image|%>
<% if @counter < 4 %>
<% p 'Im in here' %>
<% else %>
<% return %>
<% end %>
<% @counter += 1 %>
<% p @counter %>
<% end %>
Inside my loop i have an if
statement that checks if @counter
is <
than 4
.
Controller code
def show
productId = params[:id]
@product_images = ProductImage.where("product_id = ?", productId)
@counter = 0
end
When i run this code it should return once the counter is greater than 4 but i get an error that says no implicit conversion of nil into String
This is pretty straight forward code i can't seem to figure out what i'm doing wrong. It seems like it's breaking in the line
<% if @counter < 4 %>
Here is a picture of the error: