0

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!

Abhilash
  • 2,864
  • 3
  • 33
  • 67
  • The error message looks more specific to your *application code* than to the *devise*. I would suggest to check whether you have deliberately frozen the `Admin` class anywhere in your code. *Note: I tried the same and did not receive any error (I did not try the complete functionality though)* – Prabakaran Jan 13 '20 at 15:47

2 Answers2

1

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)

Thang
  • 811
  • 1
  • 5
  • 12
-1

Make Admin the inheritor of the User class. Then already delimit access rights for the User and for the Admin

  • What you are suggesting is not clear. From what I understand you are suggesting to inherit from the user model. But what's the purpose of inheriting another model? The main objective of creating separate devise models is for the logic separation(abstraction) from each other – Abhilash Jan 13 '20 at 14:31