Skip to content

Instantly share code, notes, and snippets.

@CH-JesseMa
Created May 12, 2014 21:06
Show Gist options
  • Save CH-JesseMa/9f58ba4af122d3d70c52 to your computer and use it in GitHub Desktop.
Save CH-JesseMa/9f58ba4af122d3d70c52 to your computer and use it in GitHub Desktop.
CRUD Controller (template)
class AppointmentsController < ApplicationController
def index
@appointments = Appointment.all
end
def show
@appointment = Appointment.find(params[:id])
end
def new
@appointment = Appointment.new
end
def create
@appointment = Appointment.new(appointment_params)
if @appointment.save
redirect_to @appointment
else
render 'new'
end
end
def edit
@appointment = Appointment.find(params[:id])
end
def update
@appointment = Appointment.find(params[:id])
if @appointment.update(params[:appointment].permit(
:appointment_time,
:client_email,
:client_name,
:client_mobile,
:appointment_duration,
:appointment_location))
end
end
def destroy
@appointment = Appointment.find(params[:id])
@appointment.destroy
redirect_to appointments_path
end
end
private
def appointment_params
params.require(:appointment).permit(
:appointment_time,
:client_email,
:client_name,
:client_mobile,
:appointment_duration,
:appointment_location)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment