class BookingsController

Public Instance Methods

create() click to toggle source
# 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
destroy() click to toggle source
# 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
edit() click to toggle source
# File lib/bookings/generators/templates/bookings_controller.rb, line 47
def edit
end
index() click to toggle source
# File lib/bookings/generators/templates/bookings_controller.rb, line 6
def index
  @bookings = Booking.current.order(:starts_at)
  respond_with @bookings
end
new() click to toggle source
# File lib/bookings/generators/templates/bookings_controller.rb, line 11
def new
  @booking = Booking.new
end
show() click to toggle source
# File lib/bookings/generators/templates/bookings_controller.rb, line 33
def show
  @booking = Booking.find(params[:id])
  respond_with @bookings
end
update() click to toggle source
# 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

Private Instance Methods

booking_params() click to toggle source
# File lib/bookings/generators/templates/bookings_controller.rb, line 70
def booking_params
  params[:booking].permit!
end
find_booking() click to toggle source
# File lib/bookings/generators/templates/bookings_controller.rb, line 74
def find_booking
  @booking = Booking.find(params[:id])
end