Skip to content

Instantly share code, notes, and snippets.

@h2rd
Last active August 29, 2015 14:01
Show Gist options
  • Select an option

  • Save h2rd/5242f78a640ef34f86c8 to your computer and use it in GitHub Desktop.

Select an option

Save h2rd/5242f78a640ef34f86c8 to your computer and use it in GitHub Desktop.
class Post < ActiveRecord::Base
  STATUS = %w(draft published)

  def draft?
    status == 'draft'
  end

  def published?
    status == 'published'
  end
end

changes to

class Post < ActiveRecord::Base
  enum status: %w(draft published)
end
# Query method
post.draft?
post.published?

# Action method
post.draft!
post.published!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment