Skip to content

Instantly share code, notes, and snippets.

@chrisdpeters
Last active May 21, 2017 12:22

Revisions

  1. chrisdpeters revised this gist Jul 30, 2014. 1 changed file with 11 additions and 0 deletions.
    11 changes: 11 additions & 0 deletions posts_controller.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    class Admin::PostsController < Admin::BaseController
    def index
    @posts = Post.live.includes(:draft).to_a
    @posts.map! { |post| post.draft? ? post.draft.reify : post }
    end

    def show
    @post = Post.live.find(params[:id])
    @post = @post.draft.reify if @post.draft?
    end
    end
  2. chrisdpeters revised this gist Jul 30, 2014. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions accessing_drafts.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    # Accessing drafts through the `Draftsman::Draft` class
    @drafts = Draftsman::Draft.order(:created_at)

    # Accessing a draft through a model
    @post = Post.find(params[:id])
    @draft = @post.draft if @post.draft?
  3. chrisdpeters created this gist Jul 30, 2014.
    4 changes: 4 additions & 0 deletions scopes.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    Widget.drafted # Limits to items that have drafts. Best used in an "admin" area in your application.
    Widget.published # Limits to items that have been published at some point in their lifecycles. Best used in a "public" area in your application.
    Widget.trashed # Limits to items that have been drafted for deletion (but not fully committed for deletion). Best used in an "admin" area in your application.
    Widget.live # Limits to items that have not been drafted for deletion. Best used in an "admin" area in your application.