Sha256: eb98a65b8dc73a5a5071b1b3b461433954ff678f946ba73a381a9ffb5c7551e7
Contents?: true
Size: 955 Bytes
Versions: 1
Compression:
Stored size: 955 Bytes
Contents
class AttachmentField < Field def default_input_type :file end def default Attachment.new({}, nil, self).to_hash end def untypecast(value, record) # expecting an Attachment object, or a hash of the original data value.to_hash end def typecast(value, record) Attachment.new(value, record, self) end def json_action(action, value, record) original = record.get(name) case action when 'set' return if value.nil? original.set_file(value) record.set_raw(name, original.to_hash) when 'clear' original.remove_files record.set_raw(name, nil) end record.changed!(name) end def from_json(value, record) original = record.get(name) original.set_file(value) original end def after_destroy(record) if record.get(name).is_a?(Attachment) record.get(name).remove_files end end end Field::TYPES['attachment'] = AttachmentField
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
yodel-0.0.7 | lib/yodel/models/core/fields/attachment_field.rb |