Secret Token Error in Rails App

别说谁变了你拦得住时间么 提交于 2019-12-13 05:19:28

问题


I'm running into this error on a new Rails app and it has me a bit confused. I can start the rails server and load the index page just fine, but when I try to load any other page I get

ArguemntError: A secret is required to generate an integrity hash for cookie session data. Use config.secret_token = "some secret phrase of at least 30 characters"in config/initializers/secret_token.rb

Now what makes this strange is that I have verified that I do indeed have a .secret file. I modified the secret_token.rb file to generate a random .secret file as per the Mike Hartl tutorial. I have checked that the .secret file does indeed exist. 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. 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.


回答1:


I had to switch last line of secret_token.rb from:

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.




回答2:


Make sure you have this in your environment.rb:

YourApp::Application.initialize!


来源:https://stackoverflow.com/questions/18110079/secret-token-error-in-rails-app

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