'undefined method 'new_record?' for nil:NilClass' error in ActiveAdmin with Rail has_many relationship

Asked 2 years ago, Updated 2 years ago, 98 views

ActiveAdmin in Rails implements a form method for an object with has_many relationship, but the error 'undefined method 'new_record?' for nil:NilClass' occurs.

A has_many B A has_many C

In a relationship, I want to edit B and C together while editing A.

B works well, but C doesn't...

(Actually, I found the answer, but I left it on the record because I shoveled too much yesterday.)

ruby-on-rails activeadmin

2022-09-22 19:37

1 Answers

https://stackoverflow.com/questions/7206541/activeadmin-with-has-many-problem-undefined-method-new-record

There was an answer to that. I should've searched it earlier.

A was defined with accept_nested_attributes_for B A does not have accept_nested_attributes_for C defined.

It works well if you define this only in the original model file (not in the admin folder).


2022-09-22 19:37

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.