articles_controller.rb
来自「ruby on rails web敏捷开发之路第二版 源代码」· RB 代码 · 共 87 行
RB
87 行
#---# 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 # GET /articles # GET /articles.xml def index @articles = Article.find(:all) respond_to do |format| format.html # index.rhtml format.xml { render :xml => @articles.to_xml } end end # GET /articles/1 # GET /articles/1.xml def show @article = Article.find(params[:id]) respond_to do |format| format.html # show.rhtml format.xml { render :xml => @article.to_xml } end end # GET /articles/new def new @article = Article.new end # GET /articles/1;edit def edit @article = Article.find(params[:id]) end # POST /articles # POST /articles.xml def create @article = Article.new(params[:article]) respond_to do |format| if @article.save flash[:notice] = 'Article was successfully created.' format.html { redirect_to article_url(@article) } format.xml do headers["Location"] = article_url(@article) render :nothing => true, :status => "201 Created" end else format.html { render :action => "new" } format.xml { render :xml => @article.errors.to_xml } end end end # PUT /articles/1 # PUT /articles/1.xml def update @article = Article.find(params[:id]) respond_to do |format| if @article.update_attributes(params[:article]) format.html { redirect_to article_url(@article) } format.xml { render :nothing => true } else format.html { render :action => "edit" } format.xml { render :xml => @article.errors.to_xml } end end end # DELETE /articles/1 # DELETE /articles/1.xml def destroy @article = Article.find(params[:id]) @article.destroy respond_to do |format| format.html { redirect_to articles_url } format.xml { render :nothing => true } end endend
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?