Last active
August 29, 2015 14:06
-
-
Save ryansobol/2c7dc30dd8d01ef7dd57 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 ResourcesController < ApplicationController | |
# GET /resources | |
def index | |
@resources = Resource.all | |
end | |
# GET /resources/1 | |
def show | |
@resource = Resource.find(params[:id]) | |
end | |
# GET /resources/new | |
def new | |
@resource = Resource.new | |
end | |
# GET /resources/1/edit | |
def edit | |
@resource = Resource.find(params[:id]) | |
end | |
# POST /resources | |
def create | |
@resource = Resource.new(required_params) | |
if @resource.save | |
redirect_to @resource, notice: 'Resource created' | |
else | |
render :new | |
end | |
end | |
# PATCH /resources/1 | |
def update | |
@resource = Resource.find(params[:id]) | |
if @resource.update(required_params) | |
redirect_to @resource, notice: 'Resource updated' | |
else | |
render :edit | |
end | |
end | |
# DELETE /resources/1 | |
def destroy | |
Resource.find(params[:id]).destroy | |
redirect_to resources_url, notice: 'Resource destroyed' | |
end | |
private | |
def required_params | |
permitted = %i(title body) | |
params.require(:resource).permit(permitted) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment