2016-10-06 61 views
0

我正在使用预订系统,我正在使用简单的日历宝石...我有一个预订模式,其中包括开始日期和结束日期以及房间......现在,如果客户选择逗留3天,并且他选择了同一个房间,我需要在我简单的日历中显示他住在哪个房间。 2016年10月10日至2016年10月14日 - 2016年10月14日,该特定房间将被选中....但这里的问题是它仅显示当天预订的开始日期和房间,但并未显示其余部分天预订客房... 如何我通过所有的日期如何通过简单日历宝石的开始日期和结束日期之间的所有日期

class Booking < ApplicationRecord 


alias_attribute :start_time, :start_date 

has_many :booking_rooms, :dependent => :destroy, inverse_of: :booking 
has_many :rooms, through: :booking_rooms 
end 

class BookingRoom < ApplicationRecord 
    belongs_to :room 
    belongs_to :booking, inverse_of: :booking_rooms 
end 

class Room < ApplicationRecord 

    has_many :booking_rooms 
    has_many :bookings, through: :booking_rooms 
end 
+0

我误解你的问题。请张贴相关的型号代码。 – Amadan

+0

谢谢你的回复 – edrich13

回答

0

这样的事情应该做的伎俩ü

class BookingRoom < ApplicationRecord 
def start_time 
    self.booking.start_date.to_datetime 
end 

def end_time 
    self.booking.end_date.to_datetime 
end 
+0

非常感谢这真的很适合我... – edrich13

+0

和我不得不更新简单的日历宝石2.2 – edrich13

0

你有start_time别名:

alias_attribute :start_time, :start_date 

你不必end_time属性,或别名,也没有设置用于简单日历来覆盖默认值,因此知道您的最终属性是什么。因此,简单日历认为您的Booking是一天的活动。

+0

但我如何将它传递给简单的日历宝石轨 – edrich13

+0

谢谢,这正是wat ws失踪....我试图这样做...但现在我怎么在日期之间得到显示 – edrich13

+0

应该是这样的。如果您设置了'start_time'和'end_time',则简单日历应该将'start_time..end_time'中的每个日期添加到日历中。 – Amadan

相关问题