admin_controller.rb
来自「ruby on rails web敏捷开发之路第二版 源代码」· RB 代码 · 共 57 行
RB
57 行
#---# 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 AdminController < ApplicationController def index list render :action => 'list' end # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) verify :method => :post, :only => [ :destroy, :create, :update ], :redirect_to => { :action => :list } def list @dave_pages, @daves = paginate :daves, :per_page => 10 end def show @dave = Dave.find(params[:id]) end def new @dave = Dave.new end def create @dave = Dave.new(params[:dave]) if @dave.save flash[:notice] = 'Dave was successfully created.' redirect_to :action => 'list' else render :action => 'new' end end def edit @dave = Dave.find(params[:id]) end def update @dave = Dave.find(params[:id]) if @dave.update_attributes(params[:dave]) flash[:notice] = 'Dave was successfully updated.' redirect_to :action => 'show', :id => @dave else render :action => 'edit' end end def destroy Dave.find(params[:id]).destroy redirect_to :action => 'list' endend
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?