【发布时间】:2013-04-10 10:29:43
【问题描述】:
您好,我正在开发用于房间预订的演示应用程序,用户输入他们的 start_date 和 end_date 进行房间预订。
状态是布尔类型。默认为真。
我怎样才能使状态为 false 仅在 start_date 和 end_date 之间的特定范围内。
为此,我有两个模型,分别是 Room 和 BookingDetail,如下所示
class BookingDetail < ActiveRecord::Base
belongs_to :room
belongs_to :cart
attr_accessible :member_type_id, :room_type_id, :start_date, :end_date, :room_rate_id, :room_no, :customer_id, :room_id
end
class Room < ActiveRecord::Base
belongs_to :location
has_many :room_rate
belongs_to :room_type
has_many :booking_details
belongs_to :customer
attr_accessible :room_no, :status , :location_id , :room_type_id, :room_rate_id, :start_date, :end_date
结束
【问题讨论】:
-
status不应该在BookingDetails表中吗? -
房间表中没有状态
-
但如果您的其中一个房间是从该 start_date 到 end_date 预订的,那么该房间将在全球范围内具有错误值,而不仅仅是这些日期。
-
您需要根据请求的时间状态返回状态 true\false 吗?
标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.1