0

Would appreciate it if someone could suggest what best practice/cleanest method would be in this case:

I have a User model with a couple of validation checks for when someone creates an account via my site. I want to skip these validations when someone tries to create a new User record via my api.

I have read about solutions involving creating subclasses of the model and setting flags in private methods for each class to skip validation, or using attribute accessors to set flags, not sure what would be best or if there is something better which can be done.

L457
  • 1,002
  • 1
  • 13
  • 33

1 Answers1

0

You can try:

attributes = {
      first_name: first_name,
      last_name: last_name,
      email: email,
      title: title,
      birthday: birthday,
      phone: phone,
      mobile: mobile,
    }
user.assign_attributes(attributes)
User.save!(validate: false)

This will skip validation.