]> projects.mako.cc - selectricity/blob - app/models/picture.rb
merged in changes from devel
[selectricity] / app / models / picture.rb
1 class Picture < ActiveRecord::Base
2   belongs_to :candidate
3  
4   def set_from_field(field)
5     unless field.content_type.match(/^image/)
6       return false
7     end
8     self.filename = base_part_of(field.original_filename)
9     self.filetype =  field.content_type.chomp
10     self.data = field.read
11     self
12   end
13
14   def base_part_of(filename)
15     name = File.basename(filename)
16     name.gsub(/[^\w._-]/, '')
17   end
18
19 end
20

Benjamin Mako Hill || Want to submit a patch?