Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails: undefined method `+' for nil:NilClass

I have this super simple code in my view:

<% @something.each do |something| %>

<% i = i+1 %>

<div class="row">
<div class="span1"><span class="badge untouched"><%= i %></span></div>
</div>

<% end %>

and get this error

undefined method `+' for nil:NilClass

I have the exact same code in another view and there it works! However, I'm new to rails and you see what I want to do. Maybe there is a more common way to increment an integer within an each loop? Where does this error come from?

Thanks for any help!

like image 777
DonMB Avatar asked Apr 15 '26 11:04

DonMB


1 Answers

Well, i must have a value before you can increment it.

<% i = 0 %>
<% i = i+ 1 %>
like image 76
MurifoX Avatar answered Apr 17 '26 04:04

MurifoX



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!