class Administrate::Field::NestedHasMany
Constants
- DEFAULT_ATTRIBUTES
Public Class Methods
associated_attributes(resource_class, attr)
click to toggle source
# File lib/administrate/field/nested_has_many.rb, line 64 def self.associated_attributes(resource_class, attr) dashboard_class = dashboard_for_resource(resource_class, attr) DEFAULT_ATTRIBUTES + dashboard_class.new.permitted_attributes end
dashboard_for_resource(resource_class, attr)
click to toggle source
# File lib/administrate/field/nested_has_many.rb, line 60 def self.dashboard_for_resource(resource_class, attr) "#{associated_class_name(resource_class, attr)}Dashboard".constantize end
permitted_attribute(attr, options = {})
click to toggle source
# File lib/administrate/field/nested_has_many.rb, line 69 def self.permitted_attribute(attr, options = {}) given_class_name = options[:class_name] _resource_class = if given_class_name Administrate.warn_of_deprecated_option(:class_name) given_class_name.classify else options[:resource_class] end { "#{attr}_attributes".to_sym => associated_attributes(_resource_class, attr), } end
Public Instance Methods
associated_class_name()
click to toggle source
# File lib/administrate/field/nested_has_many.rb, line 85 def associated_class_name self.class.associated_class_name(resource.class, attribute) end
associated_form()
click to toggle source
# File lib/administrate/field/nested_has_many.rb, line 95 def associated_form Administrate::Page::Form.new(associated_dashboard, new_resource) end
association_name()
click to toggle source
# File lib/administrate/field/nested_has_many.rb, line 89 def association_name options.fetch(:association_name) do associated_class_name.underscore.pluralize[/([^\/]*)$/, 1] end end
nested_fields()
click to toggle source
# File lib/administrate/field/nested_has_many.rb, line 29 def nested_fields all_fields = if Administrate::VERSION >= "0.20.0" associated_form.attributes.values.flatten else associated_form.attributes end all_fields.reject do |nested_field| skipped_fields.include?(nested_field.attribute) end end
nested_fields_for_builder(form_builder)
click to toggle source
# File lib/administrate/field/nested_has_many.rb, line 41 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 = data[form_builder.index] nested_field.instance_variable_set( "@data", resource.send(nested_field.attribute), ) end end
to_s()
click to toggle source
# File lib/administrate/field/nested_has_many.rb, line 56 def to_s data end
Private Instance Methods
new_resource()
click to toggle source
# File lib/administrate/field/nested_has_many.rb, line 101 def new_resource @new_resource ||= associated_class.new end
skipped_fields()
click to toggle source
# File lib/administrate/field/nested_has_many.rb, line 105 def skipped_fields Array(options[:skip]) end