Ruby on Rails. Increase integer in database

Viewed 1551

I have created a website using Ruby on rails and have a database with points for my users. Every user has points so I would refer to it as @user.points. I am able to view the points by using:

<%= user.points %>

I am trying to increase these points from my page as users complete a certain action. So I tried doing:

<% @user.points += 100 %>

but this doesn't seem to work. I feel there is a simple solution or I am overseeing something.

4 Answers

Add an exlamation mark to Зелёный's answer and the object gets updated directly as well:

user.increment!(:points, 1)
Related