Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View gist:c0723e6dc5478b0f914d
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
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
Something went wrong with that request. Please try again.