Search code examples
ruby-on-railsruby-on-rails-3devise-confirmable

How to change the confirmable to be optional in devise?


I have devise for authentication and I have confirmable in devise for User model.

  • I want this to be optional based on the data I send.
  • That is there is a type field in User model.
  • If I send value 1 for type then the confirmable should be present.
  • if value is 2 then there should not be confirmable and the account should be activated automatically.

How can I do this? Please help!!


Solution

  • I think you can use skip_confirmation! method here. So it will not fire confirmation mail for user and will be confirmed.

    before_save :require_confirmation, :on => :create
    
    def require_confirmation
       self.skip_confirmation! if field == "value_2"
    end