Rails console default environment

穿精又带淫゛_ 提交于 2019-11-30 13:47:25

问题


On my development machine:

$ bundle exec rails console
Loading development environment (Rails 3.2.3)
1.9.3p194 :001 > Rails.env
 => "development"

This is expected. So far, so good.

Yet on my production server (to which I have deployed using Capistrano), I get exactly the same result:

$ bundle exec rails console
Loading development environment (Rails 3.2.3)
1.9.3p194 :001 > Rails.env
 => "development"

On either machine, I can instead do:

$ bundle exec rails console production
Loading development environment (Rails 3.2.3)
1.9.3p194 :001 > Rails.env
 => "production"

My question is: on the production server, shouldn't bundle exec rails console load the production environment by default, instead of the development environment? And if not, why not?


回答1:


The rails executable can't know which environment should run on which machine.

you can put export RAILS_ENV=production in your ~/.bashrc or ~/.bash_profile file of the user you want to start the console with.




回答2:


RAILS_ENV is a variable like any other which will always default to development

if you like you can always open up '~/.bash_profile' on the production server and add this:

 alias sc="bundle exec rails console production"

then run source ~/.bash_profile to reload that file for your terminal session and you can just call sc to load up console.



来源:https://stackoverflow.com/questions/10796689/rails-console-default-environment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!