daily pastebin goal
26%
SHARE
TWEET

Untitled

a guest Jan 20th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def create
  2.       @booking = Booking.new(params[:reservations_booking])
  3.       @booking.hotel = @hotel
  4.       @booking.set_rooms( params[:room_types] ) if params[:room_types]
  5.       @booking.set_kind(:widget)
  6.  
  7.       errors = {}
  8.       user_info = params[:user_info]
  9.  
  10.       if user_info && user_info[:has_account].to_i == 0
  11.         unless User.where("email = ?", @booking.email).first
  12.           @user = User.new(:first_name => @booking.first_name, :last_name => @booking.last_name, :email => @booking.email)
  13.           @user.save
  14.           @booking.user = @user
  15.           errors[:user] = @user.errors.keys.collect{|a| a.to_s} if @user.errors.any?
  16.         else
  17.           errors[:user] = 'user_exists'
  18.         end
  19.  
  20.       elsif user_info && user_info[:has_account].to_i == 1
  21.         @user = User.where("email = ? AND telecode = ?", user_info[:email], user_info[:telecode]).first || nil #current_user
  22.         if @user
  23.           @booking.fill_user(@user)
  24.         else
  25.           errors[:user] = 'user_not_found'
  26.         end
  27.  
  28.       else
  29.         errors[:user] = 'user_invalid_data_format'
  30.       end
  31.  
  32.       @booking.submit(:full) if @booking.valid? && errors.empty?
  33.  
  34.       response = {}
  35.       if errors.any? || @booking.errors.any?
  36.         response[:status] = false
  37.         response[:errors] = { :booking => @booking.errors.keys.collect{|a| a.to_s}, :user => errors[:user] }
  38.       else
  39.         response[:status] = true
  40.       end
  41.  
  42.       respond_to do |format|
  43.         format.js { render :json => response }
  44.       end
  45.     end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top