edrich rocha edrich rocha - 16 days ago 6x
Ruby Question

how to pass all the dates between start date and end date for simple calendar gem

i am using a booking system and i am using simple calendar gem ... i have a booking model which consist of start date and end date and the room ... now now if the customer selects to stay for 3 days and he select that same room i need to show in my simple calendar that he is staying from eg. 12-10-2016 13-10-2016 14-10-2016 and that particular room is selected.... but the problem here is it only shows the start date and the room booked for that day but it does not show the rest of the days rooms booked ...
how to i pass all the dates

class Booking < ApplicationRecord

VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i

validates :start_date, presence: true
validates :end_date, presence: true
validates :guest_name, presence: true
validates :email, presence: true, format: { with: VALID_EMAIL_REGEX }

alias_attribute :start_time, :start_date

enum status: [ :approved, :blocked, :cancelled ]

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

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


class Room < ApplicationRecord
[:name, :description, :capacity, :extra_capacity ].each{ |n| validates n, presence: true }
has_many :images, dependent: :destroy, inverse_of: :room

accepts_nested_attributes_for :images, allow_destroy: true

has_many :booking_rooms
has_many :bookings, through: :booking_rooms


= month_calendar events: @bookings do |date, bookings|
%span.trigger{"data-placement" => "top", "data-toggle" =>"popover", :tabindex => "0"}= date.strftime("%e")
.head.hide AVAILABLE
- bookings.each do |booking|
- booking.booking_rooms.each do |booking_room|
= check_box_tag booking_room.room.name, booking_room.room_id, true, disabled: true
= booking_room.room.name
- Room.where.not(id: booking.booking_rooms.map(&:room_id)).each do |room|
= check_box_tag room.name, room.id
= room.name


You have the start_time alias:

alias_attribute :start_time, :start_date

You don't have end_time attribute, or alias, nor a setting for simple-calendar to override the default and so know what your end attribute is. Thus, simple-calendar thinks your Booking is a one-day event.