Search code examples
ruby-on-railsuser-presence

Overriding presence true in User model


I have the following in my models/user.rb:

validates :company, presence: true
validates :title, presence: true

I have a secondary view where I want to create a user but not require this user to enter a company and a title. How would I do that without modifying the main user.rb?

This is for Rails 3.2


Solution

  • You can do by declaring custom validations the way @BroiSatse has answered or when saving the user you can pass validate: false as argument, do this way

    @user.save(:validate => false)