Class: BookingsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
lib/bookings/generators/templates/bookings_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/bookings/generators/templates/bookings_controller.rb', line 15

def create
  @booking = Booking.new(booking_params)

  if @booking.save
    if request.xhr?
      render json: {status: :success}.to_json
    else
      redirect_to bookings_url
    end
  else
    if request.xhr?
      render json: {errors: @booking.errors.full_messages, status: :error}.to_json
    else
      render 'new'
    end
  end
end

#destroyObject



38
39
40
41
42
43
44
45
# File 'lib/bookings/generators/templates/bookings_controller.rb', line 38

def destroy
  if @booking.destroy
    flash[:notice] = "Booking: #{@booking} deleted"
    redirect_to bookings_url
  else
    render 'index'
  end
end

#editObject



47
48
# File 'lib/bookings/generators/templates/bookings_controller.rb', line 47

def edit
end

#indexObject



6
7
8
9
# File 'lib/bookings/generators/templates/bookings_controller.rb', line 6

def index
  @bookings = Booking.current.order(:starts_at)
  respond_with @bookings
end

#newObject



11
12
13
# File 'lib/bookings/generators/templates/bookings_controller.rb', line 11

def new
  @booking = Booking.new
end

#showObject



33
34
35
36
# File 'lib/bookings/generators/templates/bookings_controller.rb', line 33

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

#updateObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/bookings/generators/templates/bookings_controller.rb', line 50

def update
  if @booking.update(booking_params)
    flash[:notice] = 'Your booking was updated successfully'

    if request.xhr?
      render json: {status: :success}.to_json
    else
      redirect_to bookings_url
    end
  else
    if request.xhr?
      render json: {errors: @booking.errors.full_messages, status: :error}.to_json
    else
      render 'edit'
    end
  end
end