ruby-on-rails
  • ruby-on-rails-3.1
  • actionmailer
  • assets
  • asset-pipeline
  • 2011-09-27 42 views 6 likes 
    6

    我無法在郵件程序中使用任何形式的資產管道,無論是郵件程序本身還是視圖。如何在Mailer中使用資產?

    以下產生並清空src圖像標籤。

    <%= image_tag "emails/header-general.png" %> 
    

    空圖像標籤看起來像這樣:

    IMG ALT =「頁眉一般」

    通過模型附加文件,並在視圖中使用它的下列形式附加一個空圖片。

    attachments.inline['header.jpg'] = 'emails/header-general.png' 
    ... 
    <%= image_tag attachments['header.png'] %> 
    

    我沒有檢查路徑,甚至嘗試了多條路徑等,但沒有運氣。 請幫忙。在電子郵件中包含圖片的任何形式都會有所幫助。

    這裏是生產環境。

    Xenium::Application.configure do 
    # Settings specified here will take precedence over those in config/application.rb 
    
    # Code is not reloaded between requests 
    config.cache_classes = true 
    
    # Full error reports are disabled and caching is turned on 
    config.consider_all_requests_local  = false 
    config.action_controller.perform_caching = true 
    
    # Disable Rails's static asset server (Apache or nginx will already do this) 
    config.serve_static_assets = false 
    
    # Compress JavaScripts and CSS 
    config.assets.compress = true 
    
    # Choose the compressors to use 
    config.assets.js_compressor = :yui 
    config.assets.css_compressor = :yui 
    
    # Don't fallback to assets pipeline if a precompiled asset is missed 
    config.assets.compile = true 
    
    # Generate digests for assets URLs 
    config.assets.digest = true 
    
    # Defaults to Rails.root.join("public/assets") 
    # config.assets.manifest = YOUR_PATH 
    
    # Specifies the header that your server uses for sending files 
    # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache 
    config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx 
    
    # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 
    # config.force_ssl = true 
    
    # See everything in the log (default is :info) 
    config.log_level = :fatal 
    
    # Use a different logger for distributed setups 
    # config.logger = SyslogLogger.new 
    
    # Use a different cache store in production 
    config.cache_store = :mem_cache_store 
    
    # Enable serving of images, stylesheets, and JavaScripts from an asset server 
    #config.action_controller.asset_host = "http://asset.xenium.bg" 
    
    # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added) 
    # config.assets.precompile += %w(search.js) 
    
    # Disable delivery errors, bad email addresses will be ignored 
    config.action_mailer.raise_delivery_errors = true 
    #config.action_mailer.perform_deliveries = true 
    config.action_mailer.delivery_method = :smtp 
    config.action_mailer.smtp_settings = { 
    :address    => "localhost", 
    :port     => 25, 
    :domain    => 'xenium.bg', 
    #:user_name   => '<username>', 
    #:password    => '<password>', 
    #:authentication  => 'plain', 
    :enable_starttls_auto => false 
    } 
    
    # Enable threaded mode 
    # config.threadsafe! 
    
    # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 
    # the I18n.default_locale when a translation can not be found) 
    config.i18n.fallbacks = true 
    
    # Send deprecation notices to registered listeners 
    config.active_support.deprecation = :notify 
    end 
    

    謝謝!

    +0

    關於調試這個的一些常規技巧,這也會給你一些額外的信息來提出這個問題。 #1。如果您在普通的視圖中顯示相同的圖像,它會顯示嗎?如果是這樣,那麼爲圖像生成的URL是什麼? #2。在郵件程序版本中,src屬性實際上是空白的?請包括您的問題中生成的img標籤。 #3。在嘗試使用不同的配置來解決這個問題時,要非常小心瀏覽器緩存。即使在解決問題後,您的瀏覽器仍可能會繼續顯示「空白」圖像。 #4。作爲此問題的一部分包含您的環境配置文件。 – cailinanne

    +0

    嗨,感謝您的評論。我編輯了我的問題以包含更多內容。沒有緩存奇怪或別的東西。它似乎不工作 – YavorIvanov

    回答

    4

    按照2.3.3 Making Inline Attachments部分,創建內嵌附件,你會做如下

    attachments.inline['image.jpg'] = File.read('/path/to/image.jpg') 
    
    你的情況

    所以,它應該是

    attachments.inline['header.jpg'] = File.read("#{Rails.root}/app/assets/images/emails/header-general.png" 
    
    1

    集config.action_controller.asset_host和配置.action_mailer.asset_host,這個效果很好。

    config.action_mailer.asset_host = URL from where pick image 
    <%= image_tag image_path('logo.png') %> 
    
    相關問題