Sha256: f1455fc4981b57221b2c7bde3ac6061d44f3d6714421d3872e1d37d0f33f48f5

Contents?: true

Size: 1.22 KB

Versions: 6

Compression:

Stored size: 1.22 KB

Contents

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.published = true
      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
    end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
typo-3.99.0 app/controllers/admin/comments_controller.rb
typo-3.99.1 app/controllers/admin/comments_controller.rb
typo-3.99.3 app/controllers/admin/comments_controller.rb
typo-3.99.2 app/controllers/admin/comments_controller.rb
typo-4.0.0 app/controllers/admin/comments_controller.rb
typo-3.99.4 app/controllers/admin/comments_controller.rb