tandusrl / acts_as_bookable

A reservation plugin for Rails applications that allows resources to be bookable.
MIT License
140 stars 103 forks source link

Bookable always available? #27

Closed charlesemarsh closed 7 years ago

charlesemarsh commented 7 years ago

Hello Support,

It well may be something to do with my setup but I really have tried everything I can think of, my bookable is always available.

I'm trying to set a vehicle as bookable, the bookings are for whole days... I'm not concerned with time, only dates...

Here is my current setup, have I missed something?

vehicle.rb
class Vehicle < ActiveRecord::Base
  acts_as_bookable time_type: :fixed
end

customer.rb
class Customer < ActiveRecord::Base
  acts_as_booker  
end

vehicles_controller.rb
class VehiclesController < ApplicationController
  def create
    @vehicle = Vehicle.new(vehicle_params)
    @vehicle.schedule = IceCube::Schedule.new(Time.now.beginning_of_day, duration: 1.day)
    @vehicle.schedule.add_recurrence_rule IceCube::Rule.daily
    @vehicle.save
  end
end

booking_records_controller.rb
  ,,,,,,,
  def create
    customer = Customer.find_by_email_address(params['booking_record']['customer_id'])
    vehicle = Vehicle.find(params['booking_record']['vehicle_id'])

    begin 
      customer.book! vehicle, time: Date.parse(params['booking_record']['start_time']).beginning_of_day
    rescue ActsAsBookable::AvailabilityError => e
      binding.pry #this is never called 
    else
  end