Accessing Devise Config Variables

守給你的承諾、 提交于 2019-12-08 14:35:48

问题


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!


回答1:


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.




回答2:


The accepted answer is no longer correct. For more recent Devise versions, the config options are tacked on to the main Devise module, e.g. Devise.allow_unconfirmed_access_for.




回答3:


This answers a similar question:

OmniAuth config is stored in an omniauths_config object within a nested stragety object

Devise.omniauth_configs

returns:

{:facebook=>
  #<Devise::OmniAuth::Config:0x007fa6db95aa68
  ....

then access via symbol:

Devise.omniauth_configs[:facebook].strategy

{"setup"=>true,
 "skip_info"=>false,
 "client_id"=>nil,
 "client_secret"=>nil,
 "client_options"=>{"site"=>"https://graph.facebook.com", "authorize_url"=>"https://www.facebook.com/dialog/oauth", "token_url"=>"/oauth/access_token"},
 "authorize_params"=>{},
 "authorize_options"=>[:scope, :display, :auth_type],
 "token_params"=>{"parse"=>:query},
 "token_options"=>[],
 "auth_token_params"=>{},
 "provider_ignores_state"=>false,
 "access_token_options"=>{"header_format"=>"OAuth %s", "param_name"=>"access_token"},
 "scope"=>"email,public_profile,publish_actions",
 "info_fields"=>"email, first_name, last_name",
 "name"=>"facebook"}


来源:https://stackoverflow.com/questions/11231687/accessing-devise-config-variables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!