cirandas.net

ref: master

app/models/image.rb


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
class Image < ApplicationRecord

  attr_accessible :uploaded_data, :label, :remove_image
  attr_accessor :remove_image

  belongs_to :owner, polymorphic: true

  def self.max_size
    Image.attachment_options[:max_size]
  end

  sanitize_filename

  has_attachment :content_type => :image,
                 :storage => :file_system,
                 :path_prefix => 'public/image_uploads',
                 :resize_to => '800x600>',
                 :thumbnails => { :big      => '150x150',
                                  :thumb    => '100x100',
                                  :portrait => '64x64',
                                  :minor    => '50x50>',
                                  :icon     => '20x20!' },
                 :max_size => 10.megabytes, # remember to update validate message below
                 processor: 'Rmagick'

  validates_attachment :size => N_("{fn} of uploaded file was larger than the maximum size of 10.0 MB").fix_i18n

  extend DelayedAttachmentFu::ClassMethods
  delay_attachment_fu_thumbnails

  postgresql_attachment_fu

  def current_data
    File.file?(full_filename) ? File.read(full_filename) : nil
  end

  def public_filename *args
    "http://#{NOOSFERO_CONF['images_domain']}#{super *args}"
  end if NOOSFERO_CONF['images_domain']

  protected

  def sanitize_filename filename
    # let accents and other utf8
    # overwrite vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb
    filename
  end

end