Class: CaseForm::Element::NestedModel

Inherits:
Base
  • Object
show all
Includes:
CaseForm::ElementExt::Associationable
Defined in:
lib/case_form/element/nested_model.rb

Constant Summary

Constants inherited from Base

Base::HTML_OPTIONS

Instance Attribute Summary collapse

Attributes inherited from Base

#builder, #options

Instance Method Summary collapse

Methods included from CaseForm::ElementExt::Associationable

#association, #association_class, #association_human_model_name, #association_method, #association_type?, #associationable?, #collection_association?, #one_to_one_association?, #specific_method, #validate_nested_attributes_association

Methods included from CaseForm::ElementExt::Naming

#object_human_model_name, #sanitized_object_name, #singularize_model_name

Constructor Details

#initialize(builder, method, options = {}, &block) ⇒ NestedModel

Returns a new instance of NestedModel.



11
12
13
14
15
# File 'lib/case_form/element/nested_model.rb', line 11

def initialize(builder, method, options={}, &block)
  @method = validate_nested_attributes_association(method, builder.object)
  @block  = block
  super(builder, options)
end

Instance Attribute Details

#blockObject

Returns the value of attribute block.



9
10
11
# File 'lib/case_form/element/nested_model.rb', line 9

def block
  @block
end

#methodObject

Returns the value of attribute method.



9
10
11
# File 'lib/case_form/element/nested_model.rb', line 9

def method
  @method
end

Instance Method Details

#generateObject



17
18
19
20
21
22
# File 'lib/case_form/element/nested_model.rb', line 17

def generate
  contents = []
  contents << nested_model_contents
  contents << builder.new_object(method, :fields => (block.nil? ? options[:fields] : block)) if allow_create?
  contents.join.html_safe
end