Skip to content

Instantly share code, notes, and snippets.

@leemcalilly
Created July 30, 2013 01:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leemcalilly/c0723e6dc5478b0f914d to your computer and use it in GitHub Desktop.
Save leemcalilly/c0723e6dc5478b0f914d to your computer and use it in GitHub Desktop.
class PhotosController < ApplicationController
load_and_authorize_resource
before_filter :require_login
before_action :set_photo, only: [:show, :edit, :update, :destroy]
# GET /photos
def index
@photos = Photo.order('created_at DESC').to_a
@photo = Photo.new
end
# GET /photos/1
def show
end
# POST /photos
def create
@photo = Photo.new(photo_params)
respond_to do |format|
if @photo.save
format.html { redirect_to photos_url, notice: 'Photo created!' }
else
format.html { render action: 'index' }
end
end
end
# PATCH/PUT /photos/1
def update
respond_to do |format|
if @photo.update(photo_params)
format.html { redirect_to @photo, notice: 'Photo updated!' }
else
format.html { render action: 'edit' }
end
end
end
# DELETE /photos/1
def destroy
@photo.destroy
respond_to do |format|
format.html { redirect_to photos_url }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_photo
@photo = Photo.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def photo_params
params.require(:photo).permit(:image)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment