comments_controller.rb
来自「用ruby on rails写的一个博客程序,还不错..ruby on rail」· RB 代码 · 共 58 行
RB
58 行
class Admin::CommentsController < Admin::BaseController before_filter :get_article def index list render_action 'list' end def list @comments = @article.comments.find(:all, :order => "id DESC") end def show @comment = @article.comments.find(params[:id]) end def new @comment = @article.comments.build(params[:comment]) if request.post? and @comment.save # We should probably wave a spam filter over this, but for now, just mark it as published. @comment.mark_as_ham! flash[:notice] = 'Comment was successfully created.' redirect_to :action => 'show', :id => @comment.id end end def edit @comment = @article.comments.find(params[:id]) @comment.attributes = params[:comment] if request.post? and @comment.save flash[:notice] = 'Comment was successfully updated.' redirect_to :action => 'show', :id => @comment.id end end def destroy @comment = @article.comments.find(params[:id]) if request.post? @comment.destroy redirect_to :action => 'list' end end private def get_article @article = Article.find(params[:article_id]) if @article.nil? redirect_to '/admin' end endend
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?