Created
May 12, 2014 21:06
-
-
Save CH-JesseMa/9f58ba4af122d3d70c52 to your computer and use it in GitHub Desktop.
CRUD Controller (template)
This file contains hidden or 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 | |
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