Class: BookingsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- BookingsController
- Defined in:
- lib/bookings/generators/templates/bookings_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
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., status: :error}.to_json else render 'new' end end end |
#destroy ⇒ Object
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 |
#edit ⇒ Object
47 48 |
# File 'lib/bookings/generators/templates/bookings_controller.rb', line 47 def edit end |
#index ⇒ Object
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 |
#new ⇒ Object
11 12 13 |
# File 'lib/bookings/generators/templates/bookings_controller.rb', line 11 def new @booking = Booking.new end |
#show ⇒ Object
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 |
#update ⇒ Object
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., status: :error}.to_json else render 'edit' end end end |