app/controllers/photos_controller.rb
class PhotosController < ApplicationController
# GET /photos
# GET /photos.json
def index
@photos = Photo.all
respond_to do |format|
format.json { render json: @photos }
end
end
# GET /photos/1
# GET /photos/1.json
def show
@photo = Photo.find(params[:id])
respond_to do |format|
format.json { render json: @photo }
end
end
# GET /photos/new
# GET /photos/new.json
def new
@photo = Photo.new
respond_to do |format|
format.json { render json: @photo }
end
end
# GET /photos/1/edit
#def edit
# @photo = Photo.find(params[:id])
#
#@all_sites = Site.all
#@all_projects = Project.all
#end
# POST /photos
# POST /photos.json
def create
@photo = Photo.new(params[:photo])
respond_to do |format|
if @photo.save
format.json { render json: @photo, status: :created, location: @photo }
else
format.json { render json: @photo.errors, status: :unprocessable_entity }
end
end
end
# PUT /photos/1
# PUT /photos/1.json
def update
@photo = Photo.find(params[:id])
respond_to do |format|
if @photo.update_attributes(params[:photo])
format.json { head :no_content }
else
format.json { render json: @photo.errors, status: :unprocessable_entity }
end
end
end
# DELETE /photos/1
# DELETE /photos/1.json
def destroy
@photo = Photo.find(params[:id])
@photo.destroy
respond_to do |format|
format.json { no_content_as_json }
end
end
end