问题
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