我有一个用户模型:
class User < ActiveRecord::Base
has_secure_password
attr_accessible :email, :password, :password_confirmation, :cardnumber, :registration
validates_uniqueness_of :email
has_many :bookings
has_many :routes, :through => :bookings
end
然后是路线模型:
class Route < ActiveRecord::Base
attr_accessible :id, :departurecity, :arrivalcity, :departuretime, :arrivaltime, :train_id
has_many :stops
belongs_to :train
has_many :bookings
has_many :users, :through => :bookings
end
最终的书本模型:
class Booking < ActiveRecord::Base
attr_accessible :route_id, :user_id, :dateb, :hourb, :citydeparture, :cityarrival, :id, :tripclass
belongs_to :user
belongs_to :route
问题是如何在预订模型上制作一个方法,用户无法在同一个用户的另一个预订火车路线上预订重叠时间的火车路线?