In my Ruby on Rails 3.1 app I have a link like this:
<%= link_to 'Home', root_url %>
On My dev. machine it renders a link with "localhost:3000". On production it renders a link with an IP Address like this "83.112.12.27:8080". I would like to force rails to render the domain address instead of the IP Address. How can I set root_url?
You are looking for ActionController's default url option. So you can do something like:
class ApplicationController < ActionController::Base def default_url_options if Rails.env.production? {:host => "www.example.com"} else {} end end end
This also works for ActionMailer. As well, both can be set in your environment .rb or application.rb
# default host for mailer config.action_mailer.default_url_options = { host: 'example.com', protocol: 'https://' } # default host for controllers config.action_controller.default_url_options = { :host => "www.example.com" }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With