Skip to content

Instantly share code, notes, and snippets.

@andyh
Created June 15, 2012 11:12
Show Gist options
  • Save andyh/2935905 to your computer and use it in GitHub Desktop.
Save andyh/2935905 to your computer and use it in GitHub Desktop.
class SlidesController < ApplicationController
respond_to :html, :json, :pdf
def index
@slides = Slide.order("position")
respond_with(@slides)
end
def show
@slide = Slide.find(params[:id])
respond_with(@slide)
end
def new
@slide = Slide.new
respond_with(@slide)
end
def edit
@slide = Slide.find(params[:id])
end
def create
@slide = Slide.new(params[:slide])
@slide.save
respond_with(@slide)
end
def update
@slide = Slide.find(params[:id])
@slide.update_attributes(params[:slide])
respond_with(@slide)
end
def destroy
@slide = Slide.find(params[:id])
@slide.destroy
respond_with(@slide)
end
def sort
params[:slide].each_with_index do |id, index|
Slide.update_all({position: index+1}, {id: id})
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment