我在rails中很新,我想问一下不同数据库的请求来源。
类似的东西:
http://localhost:80 env: production database: production
http://localhost:8080 env: development database: development
http://localhost:8081 env: test database: test
我已经定义了三个环境。我只想切换!
根据this post,在我的application.rb中,我可以适应
Rails.env = ActiveSupport::StringInquirer.new('production')
到
# application.rb
if request.headers['HTTP_ORIGIN'] == 'http://localhost:80'
Rails.env = ActiveSupport::StringInquirer.new('production')
elsif request.headers['HTTP_ORIGIN'] == 'http://localhost:8080'
Rails.env = ActiveSupport::StringInquirer.new('development')
elsif request.headers['HTTP_ORIGIN'] == 'http://localhost:8081'
Rails.env = ActiveSupport::StringInquirer.new('test')
但似乎我无法访问方法headers
:
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.13/lib/rails/railtie/configurable.rb:30:in `method_missing': undefined method `request' for #<App::Application:0x3e9c088> (NoMethodError)
from C:/Sites/KML-backend/config/application.rb:88:in `<class:Application>'
from C:/Sites/KML-backend/config/application.rb:26:in `<module:App>'
from C:/Sites/KML-backend/config/application.rb:25:in `<top (required)>'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.13/lib/rails/commands.rb:53:in `require'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.13/lib/rails/commands.rb:53:in `block in <top (required)>'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.13/lib/rails/commands.rb:50:in `tap'
from C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-3.2.13/lib/rails/commands.rb:50:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
答案 0 :(得分:0)
我真的不明白你为什么要这样做,但是如何启动三台服务器呢?
RAILS_ENV="production" rails s -p 80
RAILS_ENV="development" rails s -p 8080
RAILS_ENV="test" rails s -p 8081