Skip to content

Instantly share code, notes, and snippets.

@alistairtweed
Last active April 4, 2017 07:18
Show Gist options
  • Save alistairtweed/e80fdf846635e1904638af671816d54d to your computer and use it in GitHub Desktop.
Save alistairtweed/e80fdf846635e1904638af671816d54d to your computer and use it in GitHub Desktop.
Resources Controller
class ResourcesController < ApplicationController
before_action :set_resource, only: [:show, :edit, :update, :destroy]
def index
@resources = Resource.all
end
def show
end
def new
@resource = Resource.new
end
def edit
end
def create
@resource = Resource.new(permitted_params)
if @resource.save
redirect_to @resource, notice: "Resource was successfully created."
else
flash.now[:error] = "Resource could not be created."
render :new
end
end
def update
if @resource.update(permitted_params)
redirect_to @resource, notice: "Resource was successfully updated."
else
flash.now[:error] = "Resource could not be updated."
render :edit
end
end
def destroy
@resource.destroy
redirect_to resources_url, notice: "Resource was successfully destroyed."
end
private
def permitted_params
params.require(:resource).permit([])
end
def set_resource
@resource = Resource.find(params[:id])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment