I am trying to add one to the already incremented field in the DB, but I am getting the following error: NoMethodError (undefined method
+' for false:FalseClass):`
Code:
med = Media.find(params[:media_id])
med.update_attributes({:screener_viewed => med.screener_viewed + 1})
I am just wanting to add 1
to the current value of screener_viewed, but can't get it to work.
Working Code:
Media.increment_counter(:screener_viewed, params[:media_id])
Use increment!
:
med.increment!(:screener_viewed)
Make sure that screener_viewed
is of type integer in your db.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With