I'm using both _path
and _url
helpers in a Rails 5.2.3 app. Everything works in development. When I deploy it in production, the URLs that were set with _url
helpers are printing out in the HTML as https://127.0.0.1
instead of to the actual host.
I tried adding this to config/environments/production.rb
:
config.action_controller.default_url_options = { host: 'example.com' }
but that turns the URLs into https://example.com:3000
, which breaks the links. (Puma is running on port 3000, but it's behind nginx, which is serving on port 80.)
Does anyone know what might be causing that? RAILS_ENV
is set to production
.
instead of
config.action_controller.default_url_options = { host: 'example.com' }
try this in the production.rb
Rails.application.routes.default_url_options[:host] = 'your_host.com'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.