Sha256: 6c430fc75e6c0f1953e36b16c7ea8297952109bc8e3cd56a44e93aa4039a85bb

Contents?: true

Size: 1.59 KB

Versions: 4

Compression:

Stored size: 1.59 KB

Contents

class SofaBlog::Admin::CommentsController < SofaBlog::Admin::BaseController
  
  before_filter :load_post
  before_filter :load_comment,        :only => [:show, :edit, :update, :destroy, :approve, :disapprove]
  before_filter :build_comment,  :only => [:new, :create]
  
  def index
    @comments = SofaBlog::Comment.order('created_at DESC')
  end
  
  def show
    render
  end
  
  def new
    render
  end
  
  def create
    @comment.save!
    flash[:notice] = 'Comment created'
    redirect_to :action => :index
  rescue ActiveRecord::RecordInvalid
    flash.now[:error] = 'Failed to create Comment'
    render :action => :new
  end
  
  def edit
    render
  end
  
  def update
    @comment.update_attributes(params[:comment])
    flash[:notice] = 'Comment updated'
    redirect_to :action => :index
  rescue ActiveRecord::RecordInvalid
    flash.now[:error] = 'Failed to update Comment'
    render :action => :edit
  end
  
  def destroy
    @comment.destroy
    flash[:notice] = 'Comment removed'
    redirect_to :action => :index
  end
  
  def approve
    @comment.approve!
  end
  
  def disapprove
    @comment.disapprove!
  end
  
protected
  
  def load_post
    @post = SofaBlog::Post.find(params[:post_id])
  rescue ActiveRecord::RecordNotFound
    flash[:error] = 'Blog post not found'
    redirect_to sofa_blog_admin_posts_path
  end

  def load_comment
    @comment = SofaBlog::Comment.find(params[:id])
  rescue ActiveRecord::RecordNotFound
    flash[:error] = 'Comment not found'
    redirect_to :action => :index
  end
  
  def build_comment
    @comment = @post.comments.build(params[:comment])
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sofa_blog-0.1.3 app/controllers/sofa_blog/admin/comments_controller.rb
sofa_blog-0.1.2 app/controllers/sofa_blog/admin/comments_controller.rb
sofa_blog-0.1.1 app/controllers/sofa_blog/admin/comments_controller.rb
sofa_blog-0.1.0 app/controllers/sofa_blog/admin/comments_controller.rb