Sha256: e206c07519a30e934572ec72cb518531ecc1b879fc7ce8ff0d65f91eb20257a5

Contents?: true

Size: 1.33 KB

Versions: 6

Compression:

Stored size: 1.33 KB

Contents

class Admin::Blog::PostsController < Admin::Blog::BaseController
  
  before_filter :build_post, :only => [:new, :create]
  before_filter :load_post,  :only => [:edit, :update, :destroy]
  
  def index
    @posts = if defined? WillPaginate
      Blog::Post.paginate :page => params[:page]
    elsif defined? Kaminari
      Blog::Post.page params[:page]
    else
      Blog::Post.all
    end
  end
  
  def new
    render
  end
  
  def create
    @post.save!
    flash[:notice] = 'Blog Post created'
    redirect_to :action => :edit, :id => @post
    
  rescue ActiveRecord::RecordInvalid
    flash.now[:error] = 'Failed to create Blog Post'
    render :action => :new
  end
  
  def edit
    render
  end
  
  def update
    @post.update_attributes!(params[:post])
    flash[:notice] = 'Blog Post updated'
    redirect_to :action => :edit, :id => @post
    
  rescue ActiveRecord::RecordInvalid
    flash.now[:error] = 'Failed to update Blog Post'
    render :action => :edit
  end
  
  def destroy
    @post.destroy
    flash[:notice] = 'Blog Post removed'
    redirect_to :action => :index
  end
  
protected
  
  def load_post
    @post = Blog::Post.find(params[:id])
  rescue ActiveRecord::RecordNotFound
    flash[:error] = 'Blog Post not found'
    redirect_to :action => :index
  end
  
  def build_post
    @post = Blog::Post.new(params[:post])
  end
  
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
comfy_blog-0.1.8 app/controllers/admin/blog/posts_controller.rb
comfy_blog-0.1.7 app/controllers/admin/blog/posts_controller.rb
comfy_blog-0.1.6 app/controllers/admin/blog/posts_controller.rb
comfy_blog-0.1.5 app/controllers/admin/blog/posts_controller.rb
comfy_blog-0.1.4 app/controllers/admin/blog/posts_controller.rb
comfy_blog-0.1.3 app/controllers/admin/blog/posts_controller.rb