Guest User

Untitled

a guest
Aug 15th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. #MODEL
  2. #models/reservations/booking.rb
  3. module Reservations
  4.  
  5. # Klasa reprezentująca rezerwacje.
  6. class Booking < ActiveRecord::Base
  7. set_table_name 'reservations_bookings'
  8.  
  9. include Reservations::Validations
  10.  
  11. attr_accessible :hotel_id, :start_date, :end_date, :currency,
  12. :first_name, :last_name, :email, :phone_number, :special_requests,
  13. :cc_type, :cc_number, :cc_first_name, :cc_last_name, :cc_expiration_date, :cc_cvc,
  14. :existing_bookings_rooms_attrs, :total_rake, :payed_rake,
  15. :addr_street_name, :addr_house_number, :addr_flat_number,
  16. :addr_postal_code, :addr_city, :addr_country, :full_guest_name, :room_id
  17.  
  18.  
  19. # Properties
  20. acts_as_paranoid
  21.  
  22. has_friendly_id :token, :approximate_ascii => true
  23.  
  24. end
  25. end
  26.  
  27. #MODUL
  28. #models/reservations/booking_modules/validations.rb
  29.  
  30. require 'active_support/concern'
  31.  
  32. module Reservations
  33. module Validations
  34. extend ActiveSupport::Concern
  35.  
  36. included do
  37. validates :token, :uniqueness => true, :presence => true
  38.  
  39. validates :hotel_id, :currency, :start_date, :end_date, :presence => true
  40. validate :validate_rooms
  41.  
  42. validates_date :start_date, :on_or_after => Date.today
  43. validates_date :end_date, :after => :start_date
  44.  
  45.  
  46. validates :first_name, :last_name, :presence => true, :unless => :fresh?
  47. validates :email, :email => true, :presence => true, :confirmation => true, :unless => :fresh?
  48.  
  49.  
  50. validates :total_rake, :payed_rake, :guarantee_rake, :cancel_rake, :presence => true
  51. validates_associated :credit_card, :unless => :has_credit_card?
  52.  
  53. def validate_rooms
  54. if self.has_rooms?
  55. return true
  56. else
  57. self.errors.add(:rooms, I18n.t('booking.error.no_room_chosen'))
  58. return false
  59. end
  60. end
  61.  
  62. end
  63.  
  64. end
  65.  
  66. end
  67.  
  68. #ERROR
  69.  
  70. uninitialized constant Reservations::Validations (NameError)
Add Comment
Please, Sign In to add comment