I have the following model object:
class ModelObj < ActiveRecord::Base
enum type: [:value_a, :value_b]
end
In my controller, I want to check the enum type attribute's value, but not sure how. What is the syntax for a comparison of an enumerable value in a controller?
Here's some code from a controller that doesn't work:
class SomeController < ApplicationController
def index
m = ModelObj.find(...)
if m.type == :value_a
# do this ...
end
end
end
According to the ActiveRecord::Enum documentation, you can access the enum value in various ways. Some examples:
You presented controller code you said “doesn’t work”, could it be that you need to use string comparison instead of symbols?