Created
September 18, 2014 22:46
-
-
Save cjlarose/1ae72d74d0d76e2f2e31 to your computer and use it in GitHub Desktop.
Rails 4.1 filtering by enums
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 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