Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: 74fc1e7c87
Fetching contributors…

Cannot retrieve contributors at this time

66 lines (55 sloc) 1.34 kB
class ImagesController < ApplicationController
before_action :set_image, only: [:show, :edit, :update, :destroy]
# GET /images
def index
@images = Image.all
end
# GET /images/1
def show
end
# GET /images/new
def new
@image = Image.new
end
# GET /images/1/edit
def edit
end
# POST /images
def create
if params[:file]
image = Image.create! :picture => params[:file]
render :json => {
:url => image.picture.url(:thumb)
}
else
@image = Image.new(image_params)
if @image.save
redirect_to @image, notice: 'Image was successfully created.'
else
render action: 'new'
end
end
end
# PATCH/PUT /images/1
def update
if @image.update(image_params)
redirect_to @image, notice: 'Image was successfully updated.'
else
render action: 'edit'
end
end
# DELETE /images/1
def destroy
@image.destroy
redirect_to images_url, notice: 'Image was successfully destroyed.'
end
private
# Use callbacks to share common setup or constraints between actions.
def set_image
@image = Image.find(params[:id])
end
# Only allow a trusted parameter "white list" through.
def image_params
params.require(:image).permit(:title, :caption, :height, :width)
end
end
Jump to Line
Something went wrong with that request. Please try again.