update data to database

Dear All
i am a beginner of ruby ob rails , now there is one problem i dont know
how to resolve it,there two tables ,

one is reservation,colums are:
the other is member,columns are:

member sign in to make a reservation with the points_accumulated he has,
then in the controller of reservations, i define a methos to create a
new reservation and save it to the database, everythins is ok, but how
can i update the member attributes points_accumulated and

i uses current_user.update_attributes() unser the create action of
reservation,but it doesnt work, it is nil,
any one can help me?

let’s say you got this

def create

@current_user = CurrenUser.new(params[:id])

@current_user. points_accumulated = @current_user.points_accumulated + 1



  • That’s a way and it maybe even shorter, but I dont know what are the rules you have


Just a note that you should be careful using this method to increment a value. It can cause a race condition.

A safer method is to use increment_counter since it updates the value directly in the database, not using the current attribute value on the instance

CurrentUser.increment_counter(:points_accumulated, params[:id])

There are better ways instead of mine I guess :slight_smile:

but I just wanted to show it because that may be the problem