Class: Tagcrumbs::Picture

Inherits:
Model
  • Object
show all
Defined in:
lib/tagcrumbs/resources/models/picture.rb

Overview

Each User has a Picture associated with him/her. There is a default Picture for every user that can only be updated and not destroyed. However, an uploaded Picture of a User can be destroyed which will set the Picture to the default Picture again.

Instance Method Summary collapse

Instance Method Details

#get_file(filename) ⇒ Object

Load a file from the local filesystem and set the attributes. Save the object to upload a new profile picture to the server.



16
17
18
19
20
21
22
23
24
# File 'lib/tagcrumbs/resources/models/picture.rb', line 16

def get_file(filename)
  return if filename.blank?
  
  self.file = {
    :filename => File.basename(filename),
    :mime_type => MIME::Types.type_for(filename).first.content_type,
    :content => Base64.encode64(File.read(filename))
  }
end