class Administrate::Field::NestedHasMany
Constants
- DEFAULT_ATTRIBUTES
Public Class Methods
associated_attributes(associated_resource)
click to toggle source
# File lib/worker/field/nested_has_many.rb, line 50 def self.associated_attributes(associated_resource) DEFAULT_ATTRIBUTES + dashboard_for_resource(associated_resource).new.permitted_attributes end
dashboard_for_resource(resource)
click to toggle source
# File lib/worker/field/nested_has_many.rb, line 46 def self.dashboard_for_resource(resource) "#{resource.to_s.classify}Dashboard".constantize end
permitted_attribute(associated_resource, _options = nil)
click to toggle source
# File lib/worker/field/nested_has_many.rb, line 55 def self.permitted_attribute(associated_resource, _options = nil) { "#{associated_resource}_attributes".to_sym => associated_attributes(associated_resource), } end
Public Instance Methods
associated_class_name()
click to toggle source
# File lib/worker/field/nested_has_many.rb, line 62 def associated_class_name options.fetch(:class_name, attribute.to_s.singularize.camelcase) end
associated_form()
click to toggle source
# File lib/worker/field/nested_has_many.rb, line 70 def associated_form Administrate::Page::Form.new(associated_dashboard, data) end
association_name()
click to toggle source
# File lib/worker/field/nested_has_many.rb, line 66 def association_name associated_class_name.underscore.pluralize end
nested_fields()
click to toggle source
# File lib/worker/field/nested_has_many.rb, line 21 def nested_fields associated_form.attributes.reject do |nested_field| skipped_fields.include?(nested_field.attribute) end end
nested_fields_for_builder(form_builder)
click to toggle source
# File lib/worker/field/nested_has_many.rb, line 27 def nested_fields_for_builder(form_builder) return nested_fields unless form_builder.index.is_a? Integer nested_fields.each do |nested_field| next if nested_field.resource.blank? # inject current data into field resource = nested_field.resource[form_builder.index] nested_field.instance_variable_set( "@data", resource.send(nested_field.attribute), ) end end
to_s()
click to toggle source
# File lib/worker/field/nested_has_many.rb, line 42 def to_s data end
Private Instance Methods
skipped_fields()
click to toggle source
# File lib/worker/field/nested_has_many.rb, line 76 def skipped_fields Array(options[:skip]) end