Reputation: 34093
class Car < ActiveRecord::Base
enum colors: {blue: 0, red: 1}
end
my_car.color # => "blue"
How do I get all cars with the same enum value as a certain object? I.e. in the case above, all blue cars.
This is my best bet so far:
Car.public_send(my_car.color)
Upvotes: 0
Views: 54
Reputation: 15515
Get all cars with the same color as my_car
:
Car.where(color: my_car.color)
Or if that doesn't work:
Car.where(color: Car.colors[my_car.color])
Upvotes: 1