articles_controller.rb

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

RB
63
字号
#---# 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 ArticlesController < ApplicationController  before_filter :load_article, :except => [:index, :new, :create]  # respond to /articles, method = GET  def index    @articles = Article.find(:all)  end  # respond to /articles/new, method = GET  def new    @article = Article.new  end  # respond to /articles, method = POST  def create    @article = Article.new(params[:article])    if @article.save      redirect_to article_url(@article)    else      render :action => :new    end  end  # respond to /articles/id, method = GET -- no code in controller  def show    respond_to do |format|      format.html      format.xml { render :xml => @article.to_xml }      format.yaml { render :xml => @article.to_yaml }    end    end  # /article/id;edit -- no code in controller  # def edit; end  # /article/id, method = PUT  def update    if @article.update_attributes(params[:article])      redirect_to article_url(@article)    else        render :action => :edit    end  end  # /article/id, method = DELETE  def destroy    @article.destroy    redirect_to articles_url  endprivate    def load_article    @article = Article.find(params[:id])  endend

⌨️ 快捷键说明

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