bus_booking/app/models/bus.rb

27 lines
555 B
Ruby
Raw Permalink Normal View History

2016-06-23 11:23:18 +00:00
class Bus
include Mongoid::Document
include Mongoid::Timestamps
field :bus_route, localize: true
field :departure_time, type: DateTime
field :reservation_end_time, type: DateTime
field :remark, localize: true
field :capacity, type: Integer
field :created_by
has_many :bookings
def can_reserve?
self.reservation_end_time > Time.now && self.bookings.count <= self.capacity
2016-06-23 11:23:18 +00:00
end
def posted_by
User.find(self.created_by).name rescue ""
end
def already_reserved?(user)
self.bookings.where(:user_id => user.id.to_s).count == 1
end
2016-06-23 11:23:18 +00:00
end