简体   繁体   中英

Ruby: Find an SQL record and update a boolean field

I'm using Sinatra and the mysql2 gem.

I'm trying to do a simple update of a field called "process_complete", which is a boolean.

My code is:

    user = User.first!(email: user_email)
    user.update(:process_complete => true)

I get the error:

19:30:05 web.1  |    INFO -  (0.000603s) SELECT * FROM `users` WHERE (`email` = 'user@email.com') LIMIT 1
19:30:05 web.1  | 2015-10-18 19:30:05 - Sequel::MassAssignmentRestriction - method process_complete= doesn't exist:

Am I doing something wrong here? When I look up SELECT * FROM users WHERE ( email = 'user@email.com') LIMIT 1 in mysql I see my user, and "process_complete" is set as 0 .

What am I doing wrong here?

Try the following:

user = User.where(email: user_email).first
user.process_complete = true
user.save

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM