daves_controller.rb

来自「ruby on rails web敏捷开发之路第二版 源代码」· RB 代码 · 共 85 行

RB
85
字号
#---# Excerpted from "Agile Web Development with Rails, 2nd Ed."# We make no guarantees that this code is fit for any purpose. # Visit http://www.pragmaticprogrammer.com/titles/rails2 for more book information.#---class DavesController < ApplicationController  # GET /daves  # GET /daves.xml  def index    @daves = Dave.find(:all)    respond_to do |format|      format.html # index.rhtml      format.xml  { render :xml => @daves.to_xml }    end  end  # GET /daves/1  # GET /daves/1.xml  def show    @dave = Dave.find(params[:id])    respond_to do |format|      format.html # show.rhtml      format.xml  { render :xml => @dave.to_xml }    end  end  # GET /daves/new  def new    @dave = Dave.new  end  # GET /daves/1;edit  def edit    @dave = Dave.find(params[:id])  end  # POST /daves  # POST /daves.xml  def create    @dave = Dave.new(params[:dave])    respond_to do |format|      if @dave.save        flash[:notice] = 'Dave was successfully created.'        format.html { redirect_to dave_path(@dave) }        format.xml  { head :created, :location => dave_path(@dave) }      else        format.html { render :action => "new" }        format.xml  { render :xml => @dave.errors.to_xml }      end    end  end  # PUT /daves/1  # PUT /daves/1.xml  def update    @dave = Dave.find(params[:id])    respond_to do |format|      if @dave.update_attributes(params[:dave])        flash[:notice] = 'Dave was successfully updated.'        format.html { redirect_to dave_path(@dave) }        format.xml  { head :ok }      else        format.html { render :action => "edit" }        format.xml  { render :xml => @dave.errors.to_xml }      end    end  end  # DELETE /daves/1  # DELETE /daves/1.xml  def destroy    @dave = Dave.find(params[:id])    @dave.destroy    respond_to do |format|      format.html { redirect_to daves_path }      format.xml  { head :ok }    end  endend

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?