Last active
May 21, 2017 12:22
-
-
Save chrisdpeters/8324486e91eaf9e1b1ed to your computer and use it in GitHub Desktop.
Draftsman gem: Add a draft state to your Ruby on Rails and Sinatra relational models http://blog.liveeditorcms.com/draftsman-gem-draft-state-ruby-on-rails-sinatra-relational-models/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for your work regarding draftsman kindly could you take me through how to get it up and working.I have a recipes project i would like to apply it to.