Module: E9Attributes::Helper
- Defined in:
- lib/e9_attributes/helper.rb
Instance Method Summary collapse
-
#build_associated_resource(association_name) ⇒ Object
tries to build an associated resource, looking to the assocatiaon’s model for a method named “%association_name_build_parameters}” first for any default params.
- #link_to_add_record_attribute(association_name) ⇒ Object
- #link_to_destroy_record_attribute ⇒ Object
- #record_attribute_template(association_name, builder, options = {}) ⇒ Object
- #render_record_attribute_association(association_name, form, options = {}) ⇒ Object
- #render_record_attribute_form(association_name, form) ⇒ Object
Instance Method Details
#build_associated_resource(association_name) ⇒ Object
tries to build an associated resource, looking to the assocatiaon’s model for a method named “%association_name_build_parameters}” first for any default params
41 42 43 44 45 |
# File 'lib/e9_attributes/helper.rb', line 41 def build_associated_resource(association_name) params_method = "#{association_name}_build_parameters" build_params = resource_class.send(params_method) if resource_class.respond_to?(params_method) resource.send(association_name).build(build_params || {}) end |
#link_to_add_record_attribute(association_name) ⇒ Object
3 4 5 |
# File 'lib/e9_attributes/helper.rb', line 3 def link_to_add_record_attribute(association_name) content_tag :span, t(:add_record_attribute, :scope => :e9_attributes), :class => 'add-nested-association', 'data-association' => association_name end |
#link_to_destroy_record_attribute ⇒ Object
7 8 9 |
# File 'lib/e9_attributes/helper.rb', line 7 def link_to_destroy_record_attribute content_tag :span, t(:destroy_record_attribute, :scope => :e9_attributes), :class => 'destroy-nested-association' end |
#record_attribute_template(association_name, builder, options = {}) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/e9_attributes/helper.rb', line 30 def record_attribute_template(association_name, builder, = {}) .symbolize_keys! render( :partial => [:partial] || "record_attributes/#{association_name.to_s.singularize}", :locals => { :f => builder } ) end |
#render_record_attribute_association(association_name, form, options = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/e9_attributes/helper.rb', line 18 def render_record_attribute_association(association_name, form, = {}) .symbolize_keys! association = resource.send(association_name) unless association.empty? form.fields_for(association_name) do |f| concat record_attribute_template(association_name, f, ) end end end |
#render_record_attribute_form(association_name, form) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/e9_attributes/helper.rb', line 11 def render_record_attribute_form(association_name, form) render(RecordAttribute::FORM_PARTIAL, { :form => form, :association_name => association_name }) end |