简体   繁体   English

图片未显示在Rails邮件中

[英]Image doesn't show in Rails mail

I am using Creditor, Paperclip, and Mailer (send grid) to create content and mail it to subscribers. 我正在使用Creditor,Paperclip和Mailer(发送网格)来创建内容并将其邮寄给订阅者。 I am uploading an image to my server and it shows on the website correctly in :content , however users receive a blank image in their email. 我正在将图像上传到服务器,并且该图像正确显示在网站上的:content ,但是用户在电子邮件中收到空白图像。

This is my mailer body: 这是我的邮件正文:

<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>

And my mailer: 和我的邮件:

class MessageMailer < ActionMailer::Base
  default from: "meditate@messagefollower.com"

  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

my config.js for creditor 我的债权人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;
};

my attachment.rb 我的attach.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

Most probably it is because of URLs in your @message.content are not absolute, they don't include the hostname. 这很可能是因为@message.content中的URL不是绝对的,它们不包含主机名。

Set CKEditor's config.baseHref to your site address, it defaults to empty. 将CKEditor的config.baseHref设置为您的站点地址,默认为空。

Other way is to preprocess the content and change href="/some/path" to href="http://your.address.com/some/path" . 另一种方法是预处理内容并将href="/some/path"更改为href="http://your.address.com/some/path"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM