I’m trying to set all the values to 0 but the 3rd line (send(x)) is giving me problems. Seems right to me, but doesn’t work. x is the car and name of the columns in Power. Any tips?
<% @cars.each do |x| %>
<% @power = Power.find_by_user_id(@user) %>
<% @power.send(x) = 0 %>
<% @power.save %>
<% end %>
Assuming
@carscontains column names ofPower, you need tosendthe setter method (i.e. with an=at the end). You also need to ensure you’re passing a symbol tosend.There’s also not an obvious reason why you need to set or save
@powerin the loop, so it might be better as: