3

Using Rails 4.0.0 and Ruby 2.0.0

I was looking at my _urls and _paths in my rails console and noticed

2.0.0p247 :001 > app.host
 => "www.example.com"
2.0.0p247 :001 > app.root_url
 => "http://www.example.com/"

Is setting the host to www.example.com just default behavior upon rails c startup or is there a config somewhere that sets this domain? If so, how do I set the app.host variable/config per environment?

Derek
  • 11,980
  • 26
  • 103
  • 162
  • Check if [THIS](http://stackoverflow.com/questions/2660172/how-do-i-set-default-host-for-url-helpers-in-rails) helps – Abhi Nov 27 '15 at 15:16

1 Answers1

0

In the Rails 4 console, app.host and the like access an "integration session": It is seemingly a placeholder for the console to work completely. Apparently, the app host is not configurable. See the Railties gem.

Exert from v4.0.2: railties-4.0.2/lib/rails/console/app.rb

module Rails
  module ConsoleMethods
    def app(create=false)
      @app_integration_instance = nil if create
      @app_integration_instance ||= new_session do |sess|
        sess.host! "www.example.com"
      end
    end

    def new_session
      app = Rails.application
      session = ActionDispatch::Integration::Session.new(app)
      yield session if block_given?
      session
    end
  end
end

The new_session method allows to choose the host, though.

Eric Platon
  • 9,819
  • 6
  • 41
  • 48