I had request.env['http_host']
working on localhost, but it causes an error when referenced in a layout page on heroku.
This request works in a view and displays the correct base url, but it causes an error when I move the code to the layout. Note - I'm using this to build absolute urls for images in html emails.
<%= "#{request.env['HTTP_HOST']}/assets/email_header_image.png" %>
<%= image_tag "#{request.env['HTTP_HOST']}/assets/email_header_image.png" %>
error received:
ActionView::Template::Error (undefined method `env' for nil:NilClass):
If you want the host without the port, just use:
request.host
edit: Oops, I've just noticed that you're using the code in the view. I don't know if it is visible over there, I've only used it in controllers, but that's fairly simple to overcome by setting an instance variable.
@host = request.host
<%= @host %>
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