访问设计配置变量 [英] Accessing Devise Config Variables

查看:92
本文介绍了访问设计配置变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Rails应用中,直接从视图访问Devise配置变量的方式是什么?



我想从Devise的显示 config.allow_unconfirmed_access_for :confirmable 模块。该变量设置在 devise.rb 初始化器中:

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

谢谢! p>

解决方案

在您的Devise模型上复制 devise.rb 文件中的配置,所以如果你的Devise资源是 User ,你应该可以通过 User.allow_unconfirmed_access_for 访问它。



因此,在控制器上创建一个实例变量,并为其分配此值,然后您就可以在视图中显示该值。


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!

解决方案

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.

这篇关于访问设计配置变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆