我正在构建一个项目应用程序,我需要在创建项目记录时自动生成 1 个参与者。
My model
class Project < ActiveRecord::Base
has_many :participants, dependent: :destroy, inverse_of: :project
after_create :build_a_role
private
def build_a_role
self.participant.create!(user_id: current_user.id, level: 1, participant_cat: @role.id, added_by: current_user.id)
end
end
当我尝试这个时,我得到这个错误:
undefined method `participant' for #<Project:0x007fb402707250>