在'生产'上运行rake任务并指定环境?

tim*_*one 24 rake ruby-on-rails

我在Linode有一个主机,我正在尝试对它运行Rake任务,但我收到一个mySQL错误,说它无法连接.看起来它认为它在dev上.我做了一些谷歌搜索,看到我可以做这样的事情:

bundle exec rails c
Run Code Online (Sandbox Code Playgroud)

它加载开发环境,我无法运行User.all给我一个访问被拒绝错误.

如果我跑,bundle exec rails c RAILS_ENV=production我得到错误:

Rails.env=production database is not configured (ActiveRecord::AdapterNotSpecified)
Run Code Online (Sandbox Code Playgroud)

但是,如果我通过网络访问它,一切都很好.之前我能够跑步rake db:seed,所以我知道有一些解决方法.

使用生产凭证访问mySQL可以正常工作.

有任何想法吗?

Nic*_*gan 52

试试这个:

rails c production
Run Code Online (Sandbox Code Playgroud)

或者,在开始时:

RAILS_ENV=production rails c
Run Code Online (Sandbox Code Playgroud)

RAILS_ENV=production当你把它放在最后时,它认为你作为一个论据传递.