如何为Rails中的Devise设置密钥?

时间:2014-05-15 19:29:56

标签: ruby-on-rails devise configuration secret-key

我添加了Devise gem然后按照说明运行rails generate devise:install,结果如下:

/usr/local/rvm/gems/ruby-1.9.3-p194/gems/devise-3.2.4/lib/devise/rails/routes.rb:487:in        `raise_no_secret_key': Devise.secret_key was not set. Please add the following to your Devise initializer: (RuntimeError)

config.secret_key = 'abc123'

Please ensure you restarted your application after installing Devise or setting the key.

如何'重启'我的申请?我如何以及在何处设置密钥?

2 个答案:

答案 0 :(得分:14)

为了生成秘密运行:

bundle exec rake secret

并将结果从控制台复制到设计初始值设定项(config/initializers/devise.rb

config.secret_key = '4fce3c1c860216b8......'

答案 1 :(得分:1)

您需要在config/initializers/devise.rb添加一行以设置密钥(使用更安全的随机密钥替换下面的示例值):

 config.secret_key = 'yoursecretkey'

之后只需停止Rails服务器并重新启动它。另请参阅此Stackoverflow question