module ActsAsBookable::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 ActsAsBookable::OptionsInvalid if opts are not valid for given bookable @raise ActsAsBookable::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/acts_as_bookable/booker.rb, line 42
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 = ActsAsBookable::Booking.create!(booking_params)

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