Skip to content

Instantly share code, notes, and snippets.

@antlypls
Created January 28, 2011 23:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antlypls/801235 to your computer and use it in GitHub Desktop.
Save antlypls/801235 to your computer and use it in GitHub Desktop.
class PeopleController < ApplicationController
def index
@people = Person.all
logger.info @people.inspect
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @people }
end
end
def show
@person = Person.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @person }
end
end
def new
@person = Person.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @person }
end
end
def edit
@person = Person.find(params[:id])
end
def create
@person = Person.new(params[:person])
respond_to do |format|
if @person.save
format.html { redirect_to(@person, :notice => 'Person was successfully created.') }
format.xml { render :xml => @person, :status => :created, :location => @person }
else
format.html { render :action => "new" }
format.xml { render :xml => @person.errors, :status => :unprocessable_entity }
end
end
end
def update
@person = Person.find(params[:id])
respond_to do |format|
if @person.update_attributes(params[:person])
format.html { redirect_to(@person, :notice => 'Person was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @person.errors, :status => :unprocessable_entity }
end
end
end
def destroy
@person = Person.find(params[:id])
@person.destroy
respond_to do |format|
format.html { redirect_to(people_url) }
format.xml { head :ok }
end
end
end
class Person
include Mongoid::Document
field :name, :type => String
default_scope desc(:name)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment