scaffold attendance event:references user:references attendance_rate:references
scaffold user name email
scaffold event start_time end_time
scaffold attendance_rate rate:integer #)[1 or 0], i do not want to use boolean)
協會:
event has_many :attendances
attendance belongs_to :event
user has_many :attendances
attendance belongs_to :user
問題:我怎麼能允許同一個用戶 「參加」 同一事件只有一次?
Attendance.rb:
class Attendance < ActiveRecord::Base
belongs_to :user
belongs_to :attendance_rate
belongs_to :event
validates :user_id, :attendance_rate_id, presence: true
validates_uniqueness_of :event_id, :scope => [:user_id]
end
注:上座率在事件嵌套形式創作。
唯一索引? 'validates_uniqueness_of'? – Smar