2016-03-30 46 views
1

我使用Creditor,Paperclip和Mailer(發送網格)創建內容並將其郵寄給訂閱者。我正在將圖像上傳到我的服務器,並在:content中正確顯示在網站上,但是用戶在其電子郵件中收到空白圖像。圖像不顯示在Rails郵箱

這是我的郵件正文:

<body> 
    <h3>Hi <%= @listener.name %>, </h3> 
    <p><h3>You have received a message from <%= @message.speaker.organization %></p></h3><br/> 
    <!-- <p><%= @message.speaker.fullname %> has sent a message to you.</p><br/> --> 
    <h3 style="color: #000;">Description: <strong style="font-size: 12px; color: #444;"><%= @message.description %></strong></h3><hr/> 
    <p style="font-size: 12px;"><%= raw @message.content %></p><br/> 
</body> 

我的郵件:

class MessageMailer < ActionMailer::Base 
    default from: "[email protected]" 

    def mail_message_to_listener(message, listener) 
    @message = message 
    @listener = listener 
    if @message.image? 
     message_image_path = @message.get_image_path 
     attachments[@message.image_file_name] = File.read(message_image_path) 
    end 
    mail(to: @listener.email, subject: "#{@message.title}, Part 1") 
    end 

    def mail_message_part_to_listener(messagepart, listener) 
    @messagepart = messagepart 
    @listener = listener 
    message_title = @messagepart.message.title 
    part_number = @messagepart.part_no 
    if @messagepart.image? 
     message_part_image_path = @messagepart.get_image_path 
     attachments[@messagepart.image_file_name] = File.read(message_part_image_path) 
    end 
    mail(to: @listener.email, subject: "#{part_number.ordinalize} part of #{message_title}, Part #{part_number+1}") 
    end 
end 

我config.js對債權人

CKEDITOR.editorConfig = function(config) { 
    //config.language = 'es'; //this could be any language 
    config.width = '650'; 
    config.height = '500'; 
    config.baseHref = 'http://messagefollower.com'; 



    // Filebrowser routes 
    // The location of an external file browser, that should be launched when "Browse Server" button is pressed. 
    config.filebrowserBrowseUrl = "/ckeditor/attachment_files"; 
    // The location of an external file browser, that should be launched when "Browse Server" button is pressed in the Flash dialog. 
    config.filebrowserFlashBrowseUrl = "/ckeditor/attachment_files"; 
    // The location of a script that handles file uploads in the Flash dialog. 
    config.filebrowserFlashUploadUrl = "/ckeditor/attachment_files"; 
    // The location of an external file browser, that should be launched when "Browse Server" button is pressed in the Link tab of Image dialog. 
    config.filebrowserImageBrowseLinkUrl = "/ckeditor/pictures"; 
    // The location of an external file browser, that should be launched when "Browse Server" button is pressed in the Image dialog. 
    config.filebrowserImageBrowseUrl = "/ckeditor/pictures"; 
    // The location of a script that handles file uploads in the Image dialog. 
    config.filebrowserImageUploadUrl = "/ckeditor/pictures"; 
    // The location of a script that handles file uploads. 
    config.filebrowserUploadUrl = "/ckeditor/attachment_files"; 

// You could delete or reorder any of this elements as you wish 
    config.toolbar_Menu = [ 
    { name: 'document', items: ['Source', '-', 'Save'] }, 
    { name: 'clipboard', items: ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo'] }, 
    { name: 'editing', items: ['SelectAll', '-', 'SpellChecker', 'Scayt'] }, 
    { name: 'tools', items: ['Maximize', 'ShowBlocks', '-'] }, '/', 
    { name: 'basicstyles', items: ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat'] }, 
    { name: 'paragraph', items: ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'] }, 
    { name: 'links', items: ['Link', 'Unlink', 'Anchor'] }, '/', 
    { name: 'styles', items: ['Styles', 'Format', 'Font', 'FontSize'] }, 
    { name: 'colors', items: ['TextColor', 'BGColor'] }, 
    { name: 'insert', items: ['Image', 'Table', 'HorizontalRule', 'Smiley', 'SpecialChar', 'PageBreak'] } 
    ]; 
    config.toolbar = 'Menu'; 
    return true; 
}; 

我attachment.rb

class Ckeditor::AttachmentFile < Ckeditor::Asset 
    has_attached_file :data, 
        :url => "/ckeditor_assets/attachments/:id/:filename", 
        :path => ":rails_root/public/ckeditor_assets/attachments/:id/:filename" 

    validates_attachment_presence :data 
    validates_attachment_size :data, :less_than => 100.megabytes 
    do_not_validate_attachment_file_type :data 

    def url_thumb 
    @url_thumb ||= Ckeditor::Utils.filethumb(filename) 
    end 
end 
+0

所以它在'message.content'屬性中?它將使用相對網址。你需要配置它不會。看起來像你可以從[文檔](http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-baseHref) –

+0

設置它好吧,我會試一試 – Boris

+0

我看,我指定絕對網址在我的config.js我有config.baseHref ='messagefollower.com/public/ckeditor_assets/pictures/:id/...;;;線,但在ckeditor作爲源它顯示src =「/ ckeditor_assets/pictures/10/content_kolom-300-400x400.jpg」我在哪裏修復它? – Boris

回答

0

很可能是因爲你的@message.content中的URL不是絕對的,它們不包括主機名。

將CKEditor的config.baseHref設置爲您的站點地址,默認爲空。

其他方法是預處理內容並將href="/some/path"更改爲href="http://your.address.com/some/path"

+0

我會試一試 – Boris

+0

嗨,我加了config.baseHref ='http://messagefollower.com';但靜態圖像沒有顯示在電子郵件中。還有其他建議嗎? – Boris

+0

@Boris來測試它,你不需要發送電子郵件 - 你需要html中的絕對鏈接,所以看看'@ message.content'中的'img'標籤。如果你不能讓ckeditor使這些正確,那麼在發送之前修改它 – Vasfed