module ActiveBookings::Booker::InstanceMethods

Public Instance Methods

book!(bookable, opts={}) click to toggle source

Book a bookable model

@param bookable The resource that will be booked @return The booking created @raise ActiveBookings::OptionsInvalid if opts are not valid for given bookable @raise ActiveBookings::AvailabilityError if the bookable is not available for given options @raise ActiveRecord::RecordInvalid if trying to create an invalid booking

Example:

@user.book!(@room)
# File lib/active_bookings/booker.rb, line 44
def book!(bookable, opts={})
  # check availability
  bookable.check_availability!(opts) if bookable.class.bookable?

  # create the new booking
  booking_params = opts.merge({booker: self, bookable: bookable})
  booking_class = bookable.class.reflect_on_association(:bookings).klass
  booking = booking_class.create!(booking_params)

  # reload the bookable to make changes available
  bookable.reload
  self.reload
  booking
end
booker?() click to toggle source
# File lib/active_bookings/booker.rb, line 59
def booker?
  self.class.booker?
end