comments_controller.rb
来自「ruby on rails web敏捷开发之路第二版 源代码」· RB 代码 · 共 51 行
RB
51 行
#---# 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 CommentsController < ApplicationController before_filter :find_article def new @comment = Comment.new end def edit @comment = @article.comments.find(params[:id]) end def create @comment = Comment.new(params[:comment]) if (@article.comments << @comment) redirect_to article_url(@article) else render :action => :new end end def update @comment = @article.comments.find(params[:id]) if @comment.update_attributes(params[:comment]) redirect_to article_url(@article) else render :action => :edit end end def destroy comment = @article.comments.find(params[:id].to_i) @article.comments.delete(comment) redirect_to article_url(@article) end private def find_article @article_id = params[:article_id] redirect_to articles_url unless @article_id @article = Article.find(@article_id) end end
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?