Search code examples
ruby-on-railsdevise

Setting different config for scoped devise models


In a rails app what would be the way to set different config values based on devise model? Lets say we have 2 models Admin & User. Setting config values in devise.rb will be applied in all models. How can I set a different config to one of the model? I tried like this

class Admin < ApplicationRecord
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable
  self.allow_unconfirmed_access_for =0.days
end

but getting error can't modify frozen class How can I fix this.

Thanks!


Solution

  • Found an existing StackOverflow post about your issue here. Apparently, you can override confirmation_required? method in Admin model and return false to skip the confirmation steps for Admin. Please note that it will skip sending the registration email for Admin too.

    UPDATE:

    self.allow_unconfirmed_access_for = ... or Admin.allow_unconfirmed_access_for = ... works but for old devise versions.

    For recent versions it is Devise.allow_unconfirmed_access_for =... (I think this is what you are looking for)