【问题标题】:Rails 4.2 console issues - using RAILS_ENV=developmentRails 4.2 控制台问题 - 使用 RAILS_ENV=development
【发布时间】:2015-11-27 13:37:26
【问题描述】:

尝试运行

$ rails c RAILS_ENV=development

引发了 1 个警告和 1 个错误,我不明白

# warning :
  config.eager_load is set to nil. Please update your config/environments/*.rb files accordingly:
  * development - set it to false
  * test - set it to false (unless you use a tool that preloads your test environment)
  * production - set it to true

# error
/config/initializers/devise.rb:13:in `+': no implicit conversion of nil into String (TypeError)

但是,config.eager_load 在开发环境中设置为 false

config/environment/development.rb
  Rails.application.configure do
  config.cache_classes = false
  config.eager_load = false
  …/…

查看我的 config/initializers/devise.rb(第 13 行)

config/initializers/devise.rb
Devise.setup do |config|
   …/…
  (13)  config.mailer_sender = 'no-reply@' +    Rails.application.secrets.domain_name
   …/…

导致 config/secrets.yml 文件

config/secrets.yml
  development:
      domain_name: example.com

这很好理解,因为运行 rails c(没有 RAILS_ENV),我明白了

$ rails c
  development environment (Rails 4.2.3)
  irb: warn: can't alias context from irb_context.
  irb(main):001:0>  Rails.application.secrets.domain_name

=> "example.com"

这个警告也很神秘:

irb: warn: can't alias context from irb_context

在 Google 搜索中找不到任何信息……但至少它在开发中运行……

为什么使用 RAILS_ENV 会出现此警告和错误?欢迎任何启蒙

【问题讨论】:

    标签: ruby-on-rails-4 devise rails-console


    【解决方案1】:

    太糟糕了..我应该阅读最新的 4.2 文档! 所以我根本不应该使用 RAILS_ENV !!

    $ rails 控制台登台 加载暂存环境(Rails 4.2.3) irb(main):001:0> 退出

    $ rails 控制台开发 加载开发环境(Rails 4.2.3) irb:警告:不能从 irb_context 中为上下文别名。 irb(main):001:0> 退出

    【讨论】:

      猜你喜欢
      • 2015-02-20
      • 1970-01-01
      • 2017-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-13
      • 1970-01-01
      相关资源
      最近更新 更多