【问题标题】:Rails always using production environmentRails 总是使用生产环境
【发布时间】:2014-01-28 11:05:01
【问题描述】:

我遇到了一个问题,无论我尝试在什么环境中运行 Rails,它总是会投入生产。例如:

$ rails c development
Loading production environment (Rails 3.2.16)
1.9.3p484 :001 > 

$ RAILS_ENV=development rails console
Loading production environment (Rails 3.2.16)
1.9.3p484 :001 > 

我在运行 Rails 服务器时第一次注意到这一点,它正在写入生产数据库而不是开发数据库。如果我运行“rails s -e development”,它会说它在开发中启动,但仍使用生产数据库。

这是我的配置/environment.rb

# Load the rails application
require File.expand_path('../application', __FILE__)

# Initialize the rails application
Skeletor::Application.initialize!

我尝试 grepping 整个项目以查看是否在任何地方设置了 RAILS_ENV,但我没有看到它。

【问题讨论】:

  • 你的 database.yml 文件是什么样的?
  • 在 bash/zsh/etc 中运行 env 的输出是什么?
  • 控制台中Rails.env的值是什么

标签: ruby-on-rails ruby-on-rails-3


【解决方案1】:

试运行:

RAILS_ENV=development bundle exec rails s

【讨论】:

    【解决方案2】:

    在初始化程序中,我做了“if Rails.env = 'production'”而不是“if Rails.env == 'production'”,这导致了问题。感谢大家的建议,我知道这一定很愚蠢。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-07
      • 2014-07-25
      • 2011-01-05
      • 2014-06-02
      • 2018-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多