Class: Image

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/image.rb

Constant Summary

MAIN_LOGO =
'logo'

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Instance Attribute Details

Returns the value of attribute photo_link



36
37
38
# File 'app/models/image.rb', line 36

def photo_link
  @photo_link
end

Instance Method Details

- (none) find_dimensions

this will be called after an image is uploaded.

> it will set the width and height of the image.

> It will not save the object

Parameters:

  • (none)

Returns:

  • (none)

    but does set the height and width



60
61
62
63
64
65
66
67
# File 'app/models/image.rb', line 60

def find_dimensions
  temporary = photo.queued_for_write[:original]
  filename = temporary.path unless temporary.nil?
  filename = photo.path if filename.blank?
  geometry = Paperclip::Geometry.from_file(filename)
  self.image_width  = geometry.width
  self.image_height = geometry.height
end

- (Object) photo

this constant is in /config/environments/*.rb



25
# File 'app/models/image.rb', line 25

has_attached_file :photo, PAPERCLIP_STORAGE_OPTS


51
52
53
# File 'app/models/image.rb', line 51

def photo_from_link
  self.photo_link || ''
end

- (Object) photo_from_link=(val)



44
45
46
47
48
49
# File 'app/models/image.rb', line 44

def photo_from_link=(val)
  if !val.blank?
    self.photo_link = val
    self.photo = open(val)
  end
end

- (Object) validate_photo

if there are errors from the plugin, then add a more meaningful message



70
71
72
73
74
75
76
77
# File 'app/models/image.rb', line 70

def validate_photo
  unless photo.errors.empty?
    # uncomment this to get rid of the less-than-useful interrim messages
    # errors.clear
    errors.add :attachment, "Paperclip returned errors for file '#{photo_file_name}' - check ImageMagick installation or image source file."
    false
  end
end