I have two models using Devise. Everything's properly scoped and working fine.
Now I want to set several config values differently for each model. For example, in one model I want to set allow_unconfirmed_access_for
for a few days, and in the other I do not want to allow any such unconfirmed access.
This is possible per Devise's own documentation at the top of config/initializers/devise.rb
...
# Use this hook to configure devise mailer, warden hooks and so forth.
# Many of these configuration options can be set straight in your model.
What's the syntax necessary to set variables within a model, as opposed to the initializer? I currently have this inside my model...
# Model Foo
Devise.setup do |config|
config.allow_unconfirmed_access_for = 2.days
end
# Model Bar
Devise.setup do |config|
config.allow_unconfirmed_access_for = 0.days
end
and it does not appear to be working...
Following the advice from a related post, I learned that these values are placed inside of the model to which Devise is applied. So we're just dealing with normal class variables.
I was able to get the desired results by setting the variables like so...
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable, :rememberable,
:trackable, :validatable, :timeoutable,
:confirmable, :recoverable, :lockable
# override Devise default config settings
self.allow_unconfirmed_access_for = 2.days
# ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With