Skip to content

Instantly share code, notes, and snippets.

@captproton
Created May 17, 2011 01:28
Show Gist options
  • Select an option

  • Save captproton/975711 to your computer and use it in GitHub Desktop.

Select an option

Save captproton/975711 to your computer and use it in GitHub Desktop.
animal controller
class AnimalsController < ApplicationController
# GET /animals
# GET /animals.xml
def index
@animals = Animal.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @animals }
end
end
# GET /animals/1
# GET /animals/1.xml
def show
@animal = Animal.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @animal }
end
end
# GET /animals/new
# GET /animals/new.xml
def new
@animal = Animal.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @animal }
end
end
# GET /animals/1/edit
def edit
@animal = Animal.find(params[:id])
end
# POST /animals
# POST /animals.xml
def create
@animal = Animal.new(params[:animal])
respond_to do |format|
if @animal.save
format.html { redirect_to(@animal, :notice => 'Animal was successfully created.') }
format.xml { render :xml => @animal, :status => :created, :location => @animal }
else
format.html { render :action => "new" }
format.xml { render :xml => @animal.errors, :status => :unprocessable_entity }
end
end
end
# PUT /animals/1
# PUT /animals/1.xml
def update
@animal = Animal.find(params[:id])
respond_to do |format|
if @animal.update_attributes(params[:animal])
format.html { redirect_to(@animal, :notice => 'Animal was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @animal.errors, :status => :unprocessable_entity }
end
end
end
# DELETE /animals/1
# DELETE /animals/1.xml
def destroy
@animal = Animal.find(params[:id])
@animal.destroy
respond_to do |format|
format.html { redirect_to(animals_url) }
format.xml { head :ok }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment