私は3つのモデルを持っています:
class Company < ActiveRecord::Base
has_many :employees
has_many :dogs, :through => :employees
end
class Employee < ActiveRescord::Base
belongs_to :company
has_many :dogs
end
class Dog < ActiveRecord::Base
belongs_to :employee
delegate :id, :to => :employee, :prefix => true, :allow_nil => true
end
これは完全に正常に機能し、ビューでdog.employee_idを呼び出すことができます。ただし、(既存のオブジェクトを編集するときではなく)RailsAdminで新しいインスタンスを作成する場合は、次のエラーが発生します。
RuntimeError at /dog/new
Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id
:allow_nilはtrueに設定され、他の属性の委任は正常に機能します。問題は何ですか?どうすれば修正できますか?