Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing Devise Config Variables

Tags:

In my Rails app, what would be the way to access a Devise config variable directly from a view?

I want to show config.allow_unconfirmed_access_for from Devise's :confirmable module. This variable is set in devise.rb initializer:

Devise.setup do   config.allow_unconfirmed_access_for = 3.days end 

Thanks!

like image 431
dgilperez Avatar asked Jun 27 '12 17:06

dgilperez


People also ask

How does devise authentication work?

Devise is an excellent authentication system made for Rails that allows us to easily drop-in User functionality into our project. Devise only includes an email and password for registration, let's also add our own username to our User model. We also want to have a unique index on our username.

Does devise work with Rails 7?

Our out-of-the box Devise setup is now working with Rails 7. Once again, if you'd like to refer to any of the code for this setup, or use the template wholesale for a new app, the code is available on GitHub, and you may also use it as a template repo to kick off your own Rails 7 devise projects.


1 Answers

The configurations on devise.rb file are replicated on your Devise model, so if your Devise resource is User, you should be able to access it through User.allow_unconfirmed_access_for.

So, create an instance variable on your controller and assign this value to it, and then you'll be able to show it on your view.

like image 51
Rodrigo Flores Avatar answered Nov 20 '22 12:11

Rodrigo Flores