Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validation problems on manual update of attribute value in Rails console

I have a simple problem. I want to change some field value for my User.find(1) in rails console.

I tried:

u = User.find(1) u.update_attributes(roles_mask: 3) 

And got false returned. When I check u.errors.full_messages, I see that it's because there is a problem with password validation from has_secure_password. How can I update it manually in the console?

like image 471
Marcin Doliwa Avatar asked Feb 27 '13 11:02

Marcin Doliwa


1 Answers

if you want to bypass validation, use

# skip validations but run callbacks u.update_attribute :roles_mask, 3 

or

# do the update on the sql so no validation and callback is executed u.update_column :roles_mask, 3 
like image 64
jvnill Avatar answered Sep 20 '22 09:09

jvnill