Sha256: 0bbf7b3f6d130050d5ac192d491ad44c4a40c857eb0208bd46eda57ad283855f

Contents?: true

Size: 1.11 KB

Versions: 13

Compression:

Stored size: 1.11 KB

Contents

# == Schema Information
#
# Table name: mail_template_files
#
#  id               :integer         not null, primary key
#  mail_template_id :integer
#  file             :string(255)
#  size             :integer
#  created_at       :datetime
#  updated_at       :datetime
#

class MailEngine::MailTemplateFile < ActiveRecord::Base
  mount_uploader :file, MailEngine::TemplateFileUploader

  validates :file, :presence => true

  belongs_to :mail_template
  delegate :url, :to => :file
  after_save :replace_url_in_mail_template

  def image?
    return false if attributes["file"].blank?
    File.basename(attributes["file"]) =~ /\.(j(e)?pg)|(png)|(gif)$/i
  end

  def replace_url_in_mail_template
    if self.file_changed? and self.file_was.present?
      self.mail_template.update_attribute :body,
        MailEngine::HtmlDocumentAssetsReplacer.replace_resource_in_html(
          self.mail_template.body,
          self.file_was,
          File.basename(self.file.url),
          :filename
        )
    end
  end

  def clone *args
    file_clone = super *args
    file_clone.file = File.open(self.file.path)
    file_clone
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
mail_engine-0.1.15 app/models/mail_engine/mail_template_file.rb
mail_engine-0.1.14 app/models/mail_engine/mail_template_file.rb
mail_engine-0.1.13 app/models/mail_engine/mail_template_file.rb
mail_engine-0.1.12 app/models/mail_engine/mail_template_file.rb
mail_engine-0.1.11 app/models/mail_engine/mail_template_file.rb
mail_engine-0.1.10 app/models/mail_engine/mail_template_file.rb
mail_engine-0.1.9 app/models/mail_engine/mail_template_file.rb
mail_engine-0.1.8 app/models/mail_engine/mail_template_file.rb
mail_engine-0.1.7 app/models/mail_engine/mail_template_file.rb
mail_engine-0.1.6 app/models/mail_engine/mail_template_file.rb
mail_engine-0.1.5 app/models/mail_engine/mail_template_file.rb
mail_engine-0.1.4 app/models/mail_engine/mail_template_file.rb
mail_engine-0.1.3 app/models/mail_engine/mail_template_file.rb