Created
January 28, 2011 23:28
-
-
Save antlypls/801235 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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