1 class Picture < ActiveRecord::Base
4 def set_from_field(field)
5 unless field.content_type.match(/^image/)
8 self.filename = base_part_of(field.original_filename)
9 self.filetype = field.content_type.chomp
10 self.data = field.read
14 def base_part_of(filename)
15 name = File.basename(filename)
16 name.gsub(/[^\w._-]/, '')