Image_tag in the mailbox without using asset_host

image_tag does not use the asset_host parameter that I set. Any ideas why? The only thing I can think of is to deal with the fact that this is a Mailer.

config / environment /development.rb

config.action_controller.asset_host = "http://localhost:3000" 

myMailer.rb

 <%= image_tag "logo.png", :style=>"margin-left:10px; padding-bottom:15px;" %> 

displayed as:

 <img alt="Logo" src="/images/logo.png?1303090162" style="margin-left:10px; padding-bottom:15px;" /> 

In the console:

 > MyApp::Application.config.action_controller #<OrderedHash {… :asset_host=>"http://localhost:3000", …}> 

I need an image_tag file to create the full path url because it will appear in the email.

+52
ruby-on-rails-3 actionmailer
Apr 21 '11 at 5:11
source share
3 answers

I used to be wrong. This is the solution you need (until the rails 3.1, where asset_host configurations are unified):

 config.action_mailer.asset_host = "http://localhost:3000" 
+90
Apr 22 2018-11-21T00:
source share

We need to specify both config.action_controller.asset_host and config.action_mailer.asset_host on Rails 3.1 and 3.2.

To add the host name to image_tag in both email and non-email messages, add the following to the environment file:

 config.action_controller.asset_host = 'http://localhost:3000' config.action_mailer.asset_host = config.action_controller.asset_host 

Where 'http: // localhost: 3000' should be replaced with your host url (and, if applicable, port).

This needs to be set for both action_controller and action_mailer, even in Rails 3.2.x.

+22
Sep 18 '12 at 14:56
source share

The abusive code about why you cannot do this is here:

 # actionpack/lib/action_view/helpers/asset_paths.rb, line 27 def compute_public_path(source, dir, ext = nil, include_host = true) # More code up here.... if controller && include_host has_request = controller.respond_to?(:request) source = rewrite_host_and_protocol(source, has_request) end end 

Here is an abusive file on GH: https://github.com/rails/rails/blob/master/actionpack/lib/action_view/helpers/asset_paths.rb

Since there is no controller in the ActionMailer view template, you will not receive a rewrite command based on an asset resource. This should probably be a ticket open to the core Rails team.

You can try the following configuration and see if it helps:

 config.action_mailer.default_url_options = {:host=>"localhost", :port=>3000, :protocol=>"http://"} 

I am sure it only works on url_for .

0
Apr 21 '11 at 12:11
source share



All Articles