How to set config.action_controller.default_url_options = {:host = '#''} on per environment basis

前端 未结 7 879
再見小時候
再見小時候 2020-12-12 22:20

Right now I\'m using this which works for the development host, but I have to manually change the {:host => \"\"} code when I move to production.

post.rb



        
7条回答
  •  孤街浪徒
    2020-12-12 23:20

    I know this is an old thread, but I ran into this with Ruby 2.6.3 and Rails 5.2.3. The behavior I was seeing was basically that every path I added would fail with Error during failsafe response: undefined method 'empty?' for nil:NilClass. In production it worked fine, but in my development environment, I would get the error mentioned above.


    The fix for me was add this to controllers/application_controller.rb:

    def default_url_options
      if Rails.env.production?
        Rails.application.routes.default_url_options = { host: "www.production-domain.com", protocol: 'https' }
      elsif Rails.env.development?
        Rails.application.routes.default_url_options = { host: 'localhost:3000', protocol: 'http' }
      end
    end
    

    I was then able to run my development environment on my local.

提交回复
热议问题