関連付けに関するドキュメントを見て、クラスを使用するように設定することができましたhas_many, :through。ただし、関連付けを実際に使用する方法の例が見つからないようです。
私のUserモデルhas_many :attendeesとhas_many :events, through: :attendees. 私のEventモデルhas_many :attendeesとhas_many :users, through: :attendees.
出席者モデル:
class Attendee < ActiveRecord::Base
attr_accessible :status
validates_inclusion_of :status, in: [:performing, :invited, :going, :maybe]
belongs_to :user
belongs_to :event
def status
read_attribute(:status).to_sym
end
def status=(value)
write_attribute(:status, value.to_s)
end
end
次のコードを使用してみました:
at1 = Attendee.new(user: u1, event: e1)
at1.status = :invited
at1.save
user当然のことながら、 andで大量代入エラーが発生しeventます。と宣言するのはポイント以外のようattr_accesibleです。ここで関連付けを使用し、カスタム属性を設定するにはどうすればよいですか?usereventstatus