Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 1.26 KB | None | 0 0
  1. class ReservationController < ApplicationController
  2.  
  3.   skip_before_action :verify_authenticity_token, only: :create
  4.  
  5.   before_filter :require_admin, only: [:confirm_booking, :reject_booking]
  6.  
  7.   def index
  8.     @halls_first_floor = Hall.first_floor.map { |hall| hall.to_hash }
  9.     @halls_second_floor = Hall.second_floor.map { |hall| hall.to_hash }
  10.     gon.reservation_bg = ActionController::Base.helpers.asset_path('reservation.png')
  11.  
  12.     respond_to do |format|
  13.       format.html
  14.       format.json do
  15.         render json: { halls_first_floor: @halls_first_floor, halls_second_floor: @halls_second_floor }
  16.       end
  17.     end
  18.   end
  19.  
  20.   def get_tables
  21.     render json: { tables: Table.for_hall(params[:hall_id]).map { |table| table.to_hash(params[:time]) } }
  22.   end
  23.  
  24.   def create
  25.     booking = Booking.new(table_id: params[:table_id], hall_id: params[:hall_id], start_date: params[:start_date], name: params[:name], phone: params[:phone])
  26.     if booking.save
  27.       render json: { status: :ok }
  28.     else
  29.       render json: { status: :unprocessable_entity }
  30.     end
  31.   end
  32.  
  33.   def confirm_booking
  34.     Booking.find(params[:id]).confirm!
  35.     redirect_to :back
  36.   end
  37.  
  38.   def reject_booking
  39.     Booking.find(params[:id]).reject!
  40.     redirect_to :back
  41.   end
  42.  
  43. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement