Skip to content

Instantly share code, notes, and snippets.

@cjlarose
Created September 18, 2014 22:46
Show Gist options
  • Save cjlarose/1ae72d74d0d76e2f2e31 to your computer and use it in GitHub Desktop.
Save cjlarose/1ae72d74d0d76e2f2e31 to your computer and use it in GitHub Desktop.
Rails 4.1 filtering by enums
class MyCoolModel < ActiveRecord::Base {
enum :status => [:started, :in_progress, :completed]
# What I'd like to work
scope :not_completed -> { where('status' => [:in_progress, :started]) }
# Hacky workaround
scope :not_completed -> { where('status' => MyCoolModel.statuses.values_at(:in_progress, :started)) }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment