Sha256: 9a829fa06ce6f47275cc9546c41b61815e64e8019c81c699f8b025d36f1c5e9a

Contents?: true

Size: 1.92 KB

Versions: 15

Compression:

Stored size: 1.92 KB

Contents

class Admin::PostsController < ApplicationController
  include ActionControllerMixin
  before_filter :authenticate_user! if Object.const_defined?('Devise')
  before_filter :scope_blog
  before_filter :scope_post, :only => [:destroy, :edit, :show, :update]

  # CRUD ===========================================================================================
  def index
    params[:labels] = {
      :slug => 'URL',
      :state         => 'Status',
      :updated_at    => 'Last Modified'
    }
    params[:by] ||= 'slug'
    params[:dir] ||= 'asc'
    @posts = @blog.posts.sort_by{ |p| p[params[:by]] || p[params[:by]].to_s }
    @posts.reverse! if params[:dir] == 'desc'
  end

  def show
  end

  def new
    @post = @blog.posts.build
  end

  def create
    handle_date_time params, :post, :publication_date
    @post = @blog.posts.build params[:post]

    if @post.save
      @post.publish! if params[:commit] == 'Publish' || params[:post][:state] == 'published'
      flash[:notice] = 'Successfully created post.'
      redirect_to admin_blog_post_path(@blog, @post)
    else
      render :action => 'new'
    end
  end

  def edit
  end

  def update
    handle_date_time params, :post, :publication_date

    if params[:commit] == 'Preview'
      @post = @blog.posts.new params[:post]
      render :action => 'preview', :layout => 'application'
    else
      if @post.update_attributes params[:post]
        @post.publish! if params[:commit] == "Publish"
        @post.unpublish! if params[:commit] == "Save as Draft"
        flash[:notice] = 'Successfully updated post.'
        redirect_to admin_blog_post_path(@blog, @post)
      else
        render :action => 'edit'
      end
    end
  end

  def destroy
    @post.destroy
    flash[:notice] = 'Successfully destroyed post.'
    redirect_to admin_blog_posts_url(@blog)
  end

  private

  def scope_blog
    @blog = Blog.first
  end

  def scope_post
    @post = @blog.posts.find params[:id]
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
blog_logic-1.4.0 app/controllers/admin/posts_controller.rb
blog_logic-1.3.1 app/controllers/admin/posts_controller.rb
blog_logic-1.3.0 app/controllers/admin/posts_controller.rb
blog_logic-1.2.4 app/controllers/admin/posts_controller.rb
blog_logic-1.2.3 app/controllers/admin/posts_controller.rb
blog_logic-1.2.2 app/controllers/admin/posts_controller.rb
blog_logic-1.2.1 app/controllers/admin/posts_controller.rb
blog_logic-1.2.0 app/controllers/admin/posts_controller.rb
blog_logic-1.1.9 app/controllers/admin/posts_controller.rb
blog_logic-1.1.8 app/controllers/admin/posts_controller.rb
blog_logic-1.1.7 app/controllers/admin/posts_controller.rb
blog_logic-1.1.6 app/controllers/admin/posts_controller.rb
blog_logic-1.1.5 app/controllers/admin/posts_controller.rb
blog_logic-1.1.4 app/controllers/admin/posts_controller.rb
blog_logic-1.1.3 app/controllers/admin/posts_controller.rb