Module: CaseForm::Associations
- Included in:
- FormBuilder
- Defined in:
- lib/case_form/associations.rb
Instance Method Summary collapse
- #association(method, *args, &block) ⇒ Object (also: #belongs_to, #has_one, #has_many, #habtm)
- #case_fields_for(record_or_name_or_array, *args, &block) ⇒ Object
- #destroy_object(options = {}) ⇒ Object
- #new_object(method, options = {}) ⇒ Object
Instance Method Details
#association(method, *args, &block) ⇒ Object Also known as: belongs_to, has_one, has_many, habtm
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/case_form/associations.rb', line 4 def association(method, *args, &block) association = object.class.reflect_on_association(method) raise(ArgumentError, "Association :#{method} not found in #{object.class} model") unless association = args. if .has_key?(:as) && association.macro != :has_one type, input_types = .delete(:as), [:checkbox, :radio, :select] raise(ArgumentError, "Unknown input type: #{type}. Available types: #{input_types.join(', ')}") unless input_types.include?(type.to_sym) send(type, method, ) elsif block_given? || object.respond_to?("#{method}_attributes=") Element::NestedModel.new(self, method, , &block).generate else specified_association(method, ) end end |
#case_fields_for(record_or_name_or_array, *args, &block) ⇒ Object
33 34 35 36 37 |
# File 'lib/case_form/associations.rb', line 33 def case_fields_for(record_or_name_or_array, *args, &block) = args. [:builder] = CaseForm::FormBuilder fields_for(record_or_name_or_array, *(args << ), &block) end |
#destroy_object(options = {}) ⇒ Object
29 30 31 |
# File 'lib/case_form/associations.rb', line 29 def destroy_object(={}) Element::DestructorHandle.new(self, ).generate end |
#new_object(method, options = {}) ⇒ Object
25 26 27 |
# File 'lib/case_form/associations.rb', line 25 def new_object(method, ={}) Element::GeneratorHandle.new(self, method, ).generate end |