Вопрос

Long story short, I decided to use VM for development in addition to my local machine. So when I pulled my source code inside that VM and ran rspec I received following output:

action@rails:~/workspace(master)$ rspec                                                                                                                                                                                                            
/home/action/.rvm/gems/ruby-2.0.0-p451/gems/devise-3.2.3/lib/devise/rails/routes.rb:481:in `raise_no_secret_key': Devise.secret_key was not set. Please add the following to your Devise initializer: (RuntimeError)                                                              

  config.secret_key = '...'  

I've added the key, but now I have following errors in specs:

2) Password pages user views his passwords                                                                                                                                                                                                                                      
     Failure/Error: sign_in user                                                                                                                                                                                                                                                  
     RuntimeError:                                                                                                                                                                                                                                                                
       Missing `secret_key_base` for 'test' environment, set this value in `config/secrets.yml`                                                                                                                                                                                   
     # ./spec/support/login_macros.rb:3:in `sign_in'                                                                                                                                                                                                                              
     # ./spec/features/account_pages_spec.rb:7:in `block (2 levels) in <top (required)>'       

What should be inside that file?

Это было полезно?

Решение

I just installed rails 4.1 and created a new project. The following is the default generated content of config/secrets.yml:

# Be sure to restart your server when you modify this file.

# Your secret key is used for verifying the integrity of signed cookies.
# If you change this key, all old signed cookies will become invalid!

# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
# You can use `rake secret` to generate a secure secret key.

# Make sure the secrets in this file are kept private
# if you're sharing your code publicly.

development:
  secret_key_base: 83aa0c7d6e2ed4574099514eb64bc3896fb8a71a344935fbd54705e0dd65adb897bc062fe477d03395a4d65675c833ba73ed340166be3874bfc01f43d6076385

test:
  secret_key_base: 513fb7657945b56098db290394bf23f5e11463c473fb228719428a30fd34b8b899dff3f6173c32d7e6bc028dc3276f15dcba11b684d27983d8203fb5634ce8ae

# Do not keep production secrets in the repository,
# instead read values from the environment.
production:
  secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>

Другие советы

You can generate a new key using rake secret then updating the value of config.secret_key.

$ rake secret

Use the output of the above command as the value for config.secret_key usually placed in config/initializers/devise.rb for devise. Restart rails server if you are using that as well.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top