Idear Clave Secreta no se estableció


Estoy desarrollando una aplicación Rails 4 usando la gema Active Admin para el back-end de administración. Active Admin a su vez utiliza Devise para la autenticación de usuarios. Ahora, cuando intento implementar la aplicación usando capistrano en el servidor VPS, obtengo el siguiente error:

rake aborted!
Devise.secret_key was not set. Please add the following to your Devise initializer:
config.secret_key = '-- secret key --'

Una búsqueda en Google no hace mucho por este error. ¿Alguna sugerencia por qué está lanzando un error? ¿Debo agregar la clave secreta al inicializador devise, ya que no puedo encontrar ningún lugar para establecer dicha clave de configuración en initializers/devise.rb?

Author: scarver2, 2013-08-06

16 answers

Corrí bundle update esta mañana y empecé a recibir el mismo error.

Lo agregué como una línea en config/initializers/devise.rb y el error fue corregido.

Este parece ser el commit que lo introdujo.

 83
Author: Brian,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-09-02 02:39:32

Lo que funcionó para mí en Rails 4.1 y Devise 3.2.4 está en config/initializers/devise.rb:

config.secret_key = ENV['DEVISE_SECRET_KEY'] if Rails.env.production?
 36
Author: Paul Odeon,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-12-30 01:08:17

A partir de Devise 3.2.3 para las aplicaciones Rails 4+, la ubicación de configuración de clave por defecto es YourAppName::Application.config.secret_key_base encontrado en config/initializers/secret_token.rb

 30
Author: Brandon Cook,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-07-28 23:27:30

Según changelog :

Devise utilizará las aplicaciones secret_key_base en Rails 4+ como su secret_key. Puedes cambiar esto y usar tu propio secreto cambiando el dispositivo.inicializador rb.

Fui a config/secrets.yml y cambié el valor production.

Antes:

production: 
  secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>

Después de:

production: 
  secret_key_base: string of charaters

Por supuesto, eso debería establecerse en la variable de entorno, que estableceré más adelante, pero esto al menos lo hizo funcionar. Obtuve mi cadena usando bundle exec rake secret.

 13
Author: Eric,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-02-13 11:30:30

Esto resolvió mi problema:

Agregue el código a continuación a su config/initializers/devise.archivo rb.

config.secret_key = '-- secret key --' 

Reemplace 'key clave secreta key' con su propia clave. Recomiendo almacenarlo en una variable ENV por motivos de seguridad.

 12
Author: Jean-Nicholas Hould,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-11-28 20:07:42

¿Podría ser que no corrieras rails g devise:install?

Ejecutar rails generate devise User sin el comando anterior causa este problema.

 10
Author: sascha.daniels,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-10-14 21:01:46

En config/initializers/devise.rb pongo:

config.secret_key = ENV["SECRET_KEY_BASE"] if Rails.env.production?

Porque si pones:

$ heroku config

Verás un secret_key_base para el modo production.

 9
Author: rld,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-08-04 16:13:50

Resuelvo mi problema del inicializador con este enfoque feo:

config.secret_key = 'some1234keyq23' if Rails.env == 'production'

En config/initializers/devise.po ¡Ahora funciona tanto en producción como en desarrollo !

 6
Author: Andrey Yasinishyn,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-09-13 17:11:53

Cloné mi repositorio en una nueva máquina desde git. El

config/secrets.yml 

El archivo estaba en mi.gitignore list, por lo que ese archivo no existía, y Devise no crea el archivo.

Agregué el archivo, luego volví a ejecutar

rails generate devise MODEL

Y funcionó.

 5
Author: jgrumps,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-03-24 21:09:48

Tengo el mismo problema. El problema fue causado por estas líneas en routes.rb:

devise_for :users, :skip => [:registrations]                                                   
as :user do
  get 'users/edit' => 'devise/registrations#edit', :as => 'edit_user_registration'              
  put 'users' => 'devise/registrations#update', :as => 'user_registration'                      
  get '/users/sign_out' => 'devise/sessions#destroy'                                            
end

Los comenté y después corrí:

$ rails generate devise:install

Y ha evaluado perfectamente. Y después de eso no comenté rutas.

 4
Author: ExiRe,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-02-10 12:11:28

Compruebe si su config\initializers\secret_token.rb tiene:

YourAppName::Application.config.secret_token

Debe ser:

YourAppName::Application.config.secret_key_base
 4
Author: zurbergram,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-02-13 12:12:15

Bueno, he estado siguiendo este post y probado casi todo aquí. He añadido la clave a devise.rb. Pero todavía estaba recibiendo el mismo error.

Tal vez una respuesta estúpida, pero todo lo que tenía que hacer era empujar la clave devise.rb al repositorio.

 1
Author: Philip John,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-01-08 11:00:59

Arreglo:

  1. En el servidor de producción:

    sudo -H nano /etc/environment
    
  2. Luego en el archivo agregue:

    export SECRET_KEY_BASE="yourkey"
    export DEMO03_DATABASE_PASSWORD="yourpass"
    

    Para establecer esto permanentemente, y en todo el sistema (todos los usuarios, todos los procesos) agregue la variable set

  3. En el archivo del proyecto local devise.rb:

    config.secret_key = ENV["SECRET_KEY_BASE"] if Rails.env.production?
    

Detalles técnicos:

  • Ubuntu 16.04
  • Devise (4.2.0)
  • rails 5.0.1
  • capistrano (3.7.1)
 1
Author: gotqn,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-01-18 22:36:05

Se encontró con el mismo problema con Rails 5.2.0 y Devise 4.4.1

Coloque lo siguiente en /config/initializers/devise.rb

config.secret_key = Rails.application.credentials.secret_key_base
 1
Author: Benny Paulino,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-03-09 23:39:47

Tratando de dar una respuesta algo más completa a las anteriores: Como se menciona en la documentación de la gema devise_auth_token

...Además, puede configurar otros aspectos de devise manualmente creando el dispositivo tradicional.archivo rb en config/initializers/devise.rb. Estos son algunos ejemplos de lo que puede hacer en este archivo:

Devise.setup do |config|   
# The e-mail address that mail will appear to be sent from   
# If absent, mail is sent from "[email protected]"  
config.mailer_sender = "[email protected]"

# If using rails-api, you may want to tell devise to not use ActionDispatch::Flash   
# middleware b/c rails-api does not include it.   
# See: http://stackoverflow.com/q/19600905/806956  
config.navigational_formats = [:json] end

Tuve el mismo problema, y como se menciona aquí, creé el inicializador devise, y le agregué la línea config.secret_key = ENV['DEVISE_SECRET_KEY'].

 0
Author: Amit Liber,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-08-31 15:49:51

No sé la solución correcta, pero está funcionando. Puedes intentarlo. Me clonaron mi proyecto desde mi cuenta de GitLab y cuando corro en mi servidor local, tengo un mensaje de error:

rake aborted! Devise.secret_key was not set. Please add the following to your Devise initializer: config.secret_key = '-- secret key --'

Abre config/initializers/devise.rb y añade esta línea

config.secret_key = '<%= ENV["SECRET_KEY_BASE"] %>'

Esta línea de código resuelve mi problema.

 0
Author: OguzTR,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-07-31 08:55:58