Pointing rails 4 hosts on Wednesday

Using Rails 4.0.0andRuby 2.0.0

I looked at _urlsand _pathson 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/"

Does the behavior of hostto set www.example.comto default only at startup, rails cor is there somewhere somewhere that sets this domain? If so, how do I set a variable app.hostfor each environment?

+3
source share
1 answer

In the console, Rails 4 app.hostand the like gain access to the "integration session": it appears to be a placeholder for the console to work fully. Apparently, the application host is not configured. See The Pearl of the Railways.

Run 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

new_session .

0

All Articles