Skip to content

Instantly share code, notes, and snippets.

@Dysp
Created March 13, 2017 15:52
Show Gist options
  • Save Dysp/ab1b0c505d3964bf426178cd85f62c38 to your computer and use it in GitHub Desktop.
Save Dysp/ab1b0c505d3964bf426178cd85f62c38 to your computer and use it in GitHub Desktop.
class IllnessesController < ApplicationController
before_action :set_illness, only: [:show, :edit, :update, :destroy]
# GET /illnesses
def index
@illnesses = Illness.all
end
# GET /illnesses/1
def show
end
# GET /illnesses/new
def new
@illness = Illness.new
end
# GET /illnesses/1/edit
def edit
end
# POST /illnesses
def create
@illness = Illness.new(illness_params)
respond_to do |format|
if @illness.save
format.html { redirect_to @illness, notice: 'Illness was successfully created.' }
format.json { render :show, status: :created, location: @illness }
else
format.html { render :new }
format.json { render json: @illness.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /illnesses/1
def update
respond_to do |format|
if @illness.update(illness_params)
format.html { redirect_to @illness, notice: 'Illness was successfully updated.' }
format.json { render :show, status: :ok, location: @illness }
else
format.html { render :edit }
format.json { render json: @illness.errors, status: :unprocessable_entity }
end
end
end
# DELETE /illnesses/1
def destroy
@illness.destroy
respond_to do |format|
format.html { redirect_to illnesses_url, notice: 'Illness was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_illness
@illness = Illness.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def illness_params
params.fetch(:illness, {})
end
end
Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
root 'illnesses#index'
resource :illnesses
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment