Module: SimpleAttachments::ContainerModel::Helpers
- Defined in:
- lib/simple_attachments/container_model.rb
Instance Method Summary collapse
-
#has_many_attachments(name, options = {}) ⇒ Object
Mark model as container and create association.
-
#has_one_attachment(name, options = {}) ⇒ Object
Mark model as container and create association.
Instance Method Details
#has_many_attachments(name, options = {}) ⇒ Object
Mark model as container and create association.
Syntax is identical to has_many
.
:attachments
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/simple_attachments/container_model.rb', line 11 def (name, = {}) reflection = has_many name, send(:define_method, reflection.plural_name + '_=') do || method, model = recover_vars(__method__) = send method.singularize.concat('_ids') = .map { |id| id.to_i } model.destroy_all :id => ( - ) ( - ).each do || (method, model, ) end end send :include, InstanceMethods end |
#has_one_attachment(name, options = {}) ⇒ Object
Mark model as container and create association.
Syntax is identical to has_one
.
:attachment
31 32 33 34 35 36 37 38 |
# File 'lib/simple_attachments/container_model.rb', line 31 def (name, = {}) reflection = has_one name, send(:define_method, reflection.name.to_s + '_=') do || method, model = recover_vars(__method__) (method, model, ) end send :include, InstanceMethods end |