Question

I am using Amazon S3 for file uploads and Cloudfront for serving static assets, and in my config/environments/staging.rb, i wrote

ActionController::Base.asset_host = Proc.new { |source|
  if source.include?('/assets')
    "d1xw0c7m8has5k.cloudfront.net"
  else
    "#{ENV['FOG_DIRECTORY']}.s3.amazonaws.com"
  end
}

ActionMailer::Base.asset_host = Proc.new { |source|
  if source.include?('/assets')
    "d1xw0c7m8has5k.cloudfront.net"
  else
    "#{ENV['FOG_DIRECTORY']}.s3.amazonaws.com"
  end
}

but in my my mail send by rails application i see image_tag src attribute empty? i.e. no image displayed. what wrong with this setting i could not identify, please help.

Was it helpful?

Solution

I solve this issue by putting these configuration in the block in config/environments/staging.rb

Demo::Application.configure do
  config.action_controller.asset_host = Proc.new { |source|
    if source.include?('/assets')
      "d1xw0c7m8has5k.cloudfront.net"
    else
      "#{ENV['FOG_DIRECTORY']}.s3.amazonaws.com"
    end
  }

  config.action_mailer.asset_host = Proc.new { |source|
    if source.include?('/assets')
      "http://d1xw0c7m8has5k.cloudfront.net"
    else
      "http://#{ENV['FOG_DIRECTORY']}.s3.amazonaws.com"
    end
  }

end

and it is necessary to provide protocol with action_mailer asset_host, i.e 'HTTP'

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top