Skip to content

How to determine missing accepts_nested_attributes_for when encourntering new_record?/nil error #58

@SumOys

Description

@SumOys

I was running into the new_record?/nil class issue described in the readme.

undefined method `new_record?' for nil:NilClass

        is_dynamic = f.object.new_record?
                             ^^^^^^^^^^^^

I have my models listed in a namespace, and had to apply this fix to get them to work with Administrate. For nested_has_many, the Administrate fix wasn't enough and I had to also add the class_name to the field options:

  ATTRIBUTE_TYPES = {
    country_tax_note: Field::NestedHasMany.with_options(class_name: "ColaCom::CountryTaxNote", skip: :tax_country),
    tax_state: Field::HasMany,
...
...

I tried adding the appropriate accepts_nested_attributes_for lines in my ColaCom::TaxCountry model

    has_many :country_tax_note, dependent: :destroy
    has_many :tax_state, dependent: :destroy

    accepts_nested_attributes_for :country_tax_note, reject_if: :all_blank, allow_destroy: true
    accepts_nested_attributes_for :tax_state, reject_if: :all_blank, allow_destroy: true 
    ...
    ...

but I still get this error. Is there any way to debug exactly which nested attribute I'm missing?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions