I am trying to figure out what is the best way to store an enum value in activerecord but convert it to a \'title\' for display in an app.
I.E.
Review Enum:
ActiveRecord enums is the best way to go since it's a part of the framework (since version 4.1).
Its usage is quite simple:
Migration:
class AddEnumToMyModel < ActiveRecord::Migration
def change
add_column :my_model, :status, :integer, default: 0
end
end
Model:
class MyModel < ActiveRecord::Base
enum status: [:draft, :beta, :public]
end
Then use it a will:
MyModel.draft # gets all drafts
MyModel.last.draft? # checks if the last model is draft
MyModel.last.status # gets the string description of the status of my model
For mode information refer to documentation.