Class: IronAdmin::NestedAttributesValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/iron_admin/nested_attributes_validator.rb

Overview

Guard object that validates a model declares accepts_nested_attributes_for for a given association before allowing nested form configuration.

Called during Resource.nested_associations resolution. Raises ArgumentError if the model is misconfigured.

Examples:

NestedAttributesValidator.validate!(Order, :line_items)

Class Method Summary collapse

Class Method Details

.validate!(model_class, association_name) ⇒ void

This method returns an undefined value.

Parameters:

  • model_class (Class)

    The ActiveRecord model class

  • association_name (Symbol, String)

    The association name to check

Raises:

  • (ArgumentError)

    if the model does not declare accepts_nested_attributes_for



17
18
19
20
21
22
23
# File 'lib/iron_admin/nested_attributes_validator.rb', line 17

def self.validate!(model_class, association_name)
  return if model_class.nested_attributes_options.key?(association_name.to_sym)

  raise ArgumentError,
        "#{model_class} must declare `accepts_nested_attributes_for :#{association_name}` " \
        "to use nested forms in IronAdmin"
end