Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update attributes without validation

You can do something like:

object.attribute = value
object.save(:validate => false)

USE update_attribute instead of update_attributes

Updates a single attribute and saves the record without going through the normal validation procedure.

if a.update_attribute('state', a.state)

Note:- 'update_attribute' update only one attribute at a time from the code given in question i think it will work for you.


try using

@record.assign_attributes({ ... })
@record.save(validate: false)

works for me


Yo can use:

a.update_column :state, a.state

Check: http://apidock.com/rails/ActiveRecord/Persistence/update_column

Updates a single attribute of an object, without calling save.


All the validation from model are skipped when we use validate: false

user = User.new(....)
user.save(validate: false)