Created
March 2, 2016 20:12
-
-
Save austinklenk/5d8b3278f4d81316f899 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AppointmentsController < ApplicationController | |
before_action :set_appointment, only: [:show, :edit, :update, :destroy] | |
# GET /appointments | |
# GET /appointments.json | |
def index | |
@appointments = @camper.appointments | |
end | |
# GET /appointments/1 | |
# GET /appointments/1.json | |
def show | |
@orders = @appointment.orders | |
respond_to do |format| | |
format.html | |
format.json | |
end | |
end | |
# GET /appointments/new | |
def new | |
@camper = Camper.find(params[:camper_id]) | |
@appointment = @camper.appointments.build | |
end | |
# GET /appointments/1/edit | |
def edit | |
end | |
# POST /appointments | |
# POST /appointments.json | |
def create | |
@appointment = Appointment.new(appointment_params) | |
respond_to do |format| | |
if @appointment.save | |
format.html { redirect_to appointment_path(@appointment), notice: 'Appointment was successfully created.' } | |
format.json { render :show, status: :created, location: @appointment } | |
else | |
format.html { render :new } | |
format.json { render json: @appointment.errors, status: :unprocessable_entity } | |
end | |
end | |
end | |
# PATCH/PUT /appointments/1 | |
# PATCH/PUT /appointments/1.json | |
def update | |
respond_to do |format| | |
if @appointment.update(appointment_params) | |
format.html { redirect_to @appointment, notice: 'Appointment was successfully updated.' } | |
format.json { render :show, status: :ok, location: @appointment } | |
else | |
format.html { render :edit } | |
format.json { render json: @appointment.errors, status: :unprocessable_entity } | |
end | |
end | |
end | |
# DELETE /appointments/1 | |
# DELETE /appointments/1.json | |
def destroy | |
@appointment.destroy | |
respond_to do |format| | |
format.html { redirect_to camper_appointments_path(@appointment), notice: 'Appointment was successfully deleted.' } | |
format.json { head :no_content } | |
end | |
end | |
private | |
# Use callbacks to share common setup or constraints between actions. | |
def set_appointment | |
@appointment = Appointment.find(params[:id]) | |
end | |
# Never trust parameters from the scary internet, only allow the white list through. | |
def appointment_params | |
params.require(:appointment).permit(:customer_id, :camper_id, :order_id, :title, :description, :date_in, :date_out) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment