class Administrate::Field::NestedHasMany
Constants
- DEFAULT_ATTRIBUTES
Public Class Methods
associated_attributes(associated_resource, options)
click to toggle source
# File lib/viniBaxter/spa/nested_has_many.rb, line 52 def self.associated_attributes(associated_resource, options) dashboard_class = dashboard_for_resource(associated_resource, options) DEFAULT_ATTRIBUTES + dashboard_class.new.permitted_attributes end
dashboard_for_resource(resource, options)
click to toggle source
# File lib/viniBaxter/spa/nested_has_many.rb, line 47 def self.dashboard_for_resource(resource, options) class_name = options && options[:class_name] || resource.to_s.classify "#{class_name}Dashboard".constantize end
permitted_attribute(associated_resource, options = nil)
click to toggle source
# File lib/viniBaxter/spa/nested_has_many.rb, line 57 def self.permitted_attribute(associated_resource, options = nil) { "#{associated_resource}_attributes".to_sym => associated_attributes(associated_resource, options), } end
Public Instance Methods
associated_class_name()
click to toggle source
# File lib/viniBaxter/spa/nested_has_many.rb, line 64 def associated_class_name options.fetch(:class_name, attribute.to_s.singularize.camelcase) end
associated_form()
click to toggle source
# File lib/viniBaxter/spa/nested_has_many.rb, line 75 def associated_form Administrate::Page::Form.new(associated_dashboard, new_resource) end
association_name()
click to toggle source
# File lib/viniBaxter/spa/nested_has_many.rb, line 68 def association_name options.fetch( :association_name, associated_class_name.underscore.pluralize[/([^\/]*)$/, 1], ) end
nested_fields()
click to toggle source
# File lib/viniBaxter/spa/nested_has_many.rb, line 22 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/viniBaxter/spa/nested_has_many.rb, line 28 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/viniBaxter/spa/nested_has_many.rb, line 43 def to_s data end
Private Instance Methods
new_resource()
click to toggle source
# File lib/viniBaxter/spa/nested_has_many.rb, line 81 def new_resource @new_resource ||= associated_class_name.constantize.new end
skipped_fields()
click to toggle source
# File lib/viniBaxter/spa/nested_has_many.rb, line 85 def skipped_fields Array(options[:skip]) end