整天但找不到简单的问题。为什么我的嵌套属性不能使用此关联?
Here is error: NoMethodError (undefined method `build_priority' for
#<Audit:0x134234jnjn2j>): app/controllers/audits_controller.rb:43:in `new'
audits_controller.rb
def new
@audit = Audit.new
@audit.build_priority
end
audit.rb模型
has_many :priorities, dependent: :destroy
accepts_nested_attributes_for :priorities, allow_destroy: true, reject_if: :all_blank
priority.rb模型
class Priority < ActiveRecord::Base
belongs_to :audit
accepts_nested_attributes_for :audit, allow_destroy: true, reject_if: :all_blank
end
def new
@audit = Audit.new
@audit.priorities.build
end
楷模:-
class Audit < ActiveRecord::Base
has_many :priorities, dependent: :destroy
accepts_nested_attributes_for :priorities, allow_destroy: true, reject_if: :all_blank
end
class Priority < ActiveRecord::Base
belongs_to :audit
#accepts_nested_attributes_for :audit, allow_destroy: true, reject_if: :all_blank
end