File size: 769 Bytes
f5071ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
class Api::BookingsController < ApplicationController

    def show
        @booking = Booking.find(params[:id])
        render :show
    end

    def index
        @bookings = Booking.all
        render :index
    end

    def create
        @booking = Booking.new(booking_params)
        @booking.guest_id = current_user.id 

        if @booking.save
            render 'api/bookings/show'
        else
            render json: @booking.errors.full_messages, status: 422
        end

    end

    def destroy
        @booking = Booking.find(params[:id])
        @booking.destroy

        render json: @booking
    end

   

    private
    def booking_params
        params.require(:booking).permit(:guest_id,:spot_id,:check_in,:check_out,:num_guest)
    end
    
end