I'm pretty new in rails and I would like to ask different database regarding to the origin of the request.
Something like :
http://localhost:80 env: production database: production
http://localhost:8080 env: development database: development
http://localhost:8081 env: test database: test
I already have my three environments defined. I just want to switch !
According to this post, in my application.rb I could adapt
Rails.env = ActiveSupport::StringInquirer.new('production')
to
# 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')
but it seems I haven't access to method 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>'