Ruby On Rails : Engineyard : ActionMailer’s asset_url helper method not working as expected

I have been using Engineyard as PaaS for deploying my Ruby On Rails application. To have my app server intact I have created a utility instance called ‘redis’ to host Redis-Server and Sidekiq.

Implementation:

 # RAILS_ENV = PRODUCTION
 #
 # Gets the logo URL of the Organization set by Controller/Mailer
 #   in instance variable @organization
 # @param [Organization] organization default value is nil
 # @return [String] URL for logo image
 def get_logo_url(organization = nil)
   if organization && organization.logo.present?
     organization.logo
   else
     # There is 'logo.png' inside /app/assets/images/
     asset_url('logo.png')
   end
 end

Problem I faced:

When condition is

organization.logo.present? == false

then it is supposed to generate a URL like http://my_site.com/assets/logo-3ea57f3386c3ee5fa0d6de2829550a55.png however, http://my_site.com/logo.png is generated. Point to be noted is, there isn’t even /assets/ included in the URL.

# source: app/config/environment/production.rb 
#
# Disable Rails's static asset server (Apache or nginx will already do this).
 config.serve_static_assets = false

 # Compress JavaScripts and CSS.
 config.assets.js_compressor = :uglifier
 config.assets.css_compressor = :sass

 # Do not fallback to assets pipeline if a pre-compiled asset is missed.
 config.assets.compile = false

 # Generate digests for assets URLs.
 config.assets.digest = true
 # Source: app/config/application.rb
 #
 # Helps helper methods like 'asset_path' to get absolute path of asset
 if ENV['HOST'] && ENV['HOST'][0..3].downcase == 'http'
   config.action_mailer.asset_host = ENV['HOST']
 else
   # 'http://' is prepended assuming ENV['HOST'] = 'mysite.com'
   config.action_mailer.asset_host = 'http://' + ENV['HOST'] rescue ''
 end

Solution:

yet to find. Please comment if you have any idea.

One thought on “Ruby On Rails : Engineyard : ActionMailer’s asset_url helper method not working as expected

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s