简体   繁体   English

Rails应用中的秘密令牌错误

[英]Secret Token Error in Rails App

I'm running into this error on a new Rails app and it has me a bit confused. 我在新的Rails应用程序上遇到此错误,这让我有些困惑。 I can start the rails server and load the index page just fine, but when I try to load any other page I get 我可以启动Rails服务器并很好地加载索引页面,但是当我尝试加载任何其他页面时,我得到了

ArguemntError: A secret is required to generate an integrity hash for cookie session data. ArguemntError:需要一个秘密来为cookie会话数据生成完整性哈希。 Use config.secret_token = "some secret phrase of at least 30 characters"in config/initializers/secret_token.rb 在config / initializers / secret_token.rb中使用config.secret_token =“至少30个字符的一些秘密短语”

Now what makes this strange is that I have verified that I do indeed have a .secret file. 现在让这个奇怪的是,我已经验证了我确实有一个.secret文件。 I modified the secret_token.rb file to generate a random .secret file as per the Mike Hartl tutorial. 根据Mike Hartl教程,我修改了secret_token.rb文件以生成一个随机的.secret文件。 I have checked that the .secret file does indeed exist. 我检查了.secret文件是否确实存在。 In fact, I deleted it and restarted the server just to make sure it would generate a new one, and it did. 实际上,我删除了它,然后重新启动服务器,以确保它会生成一个新的服务器,并且确实如此。 The contents of the .secret file do indeed contain a string of greater than 30 characters. .secret文件的内容确实包含一个大于30个字符的字符串。 And yet I am getting this error. 但是我得到这个错误。 I'm not sure what I'm missing here. 我不确定我在这里缺少什么。

I did some googling and it appears that some felt this error was related to a race condition caused by accessing the site too soon after starting the server. 我做了一些谷歌搜索,似乎有些人认为此错误与启动服务器后过早访问该站点导致的竞争状况有关。 I restarted the server, waiting five minutes, and then accessed the site. 我重新启动服务器,等待五分钟,然后访问该站点。 Same issue. 同样的问题。 I am at a loss to understand why I am getting this error. 我茫然不明白为什么我会收到此错误。 Any help would be greatly appreciated. 任何帮助将不胜感激。

I had to switch last line of secret_token.rb from: 我不得不将secret_token.rb的最后一行从:

SampleApp::Application.config.secret_key_base = secure_token

to: 至:

Todo::Application.config.secret_token = secure_token

Took reading the error message over and over though. 反复阅读错误消息。

确保您的环境中有此文件。rb:

YourApp::Application.initialize!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM