跨越边界: REST on Rails-Java频道-中国IT实验室

273阅读 0评论2008-10-17 EA6C5jp
分类:

class PeopleController < ApplicationController
  def index
    list
    render :action => 'list'
  end
  # GETs should be safe (see  
)
  verify :method => :post, :only => [ :destroy, :create, :update 
],
         :redirect_to => { :action => :list }
  def list
    @person_pages, @people = paginate :people, :per_page => 10
  end
  def show
    @person = Person.find(params[:id])
  end
  def new
    @person = Person.new
  end
  def create
    @person = Person.new(params[:person])
    if @person.save
      flash[:notice] = 'Person was successfully created.'
      redirect_to :action => 'list'
    else
      render :action => 'new'
    end
  end
  def edit
    @person = Person.find(params[:id])
  end
  def update
    @person = Person.find(params[:id])
    if @person.update_attributes(params[:person])
      flash[:notice] = 'Person was successfully updated.'
      redirect_to :action => 'show', :id => @person
    else
      render :action => 'edit'
    end
  end
  def destroy
    Person.find(params[:id])。destroy
    redirect_to :action => 'list'
  end
end
      

--------------------next---------------------

上一篇:实战 Groovy: 用 Groovy 减少代码冗余-Java频道-中国IT实验室
下一篇:网络基础:子网掩码的设置和作用