I want to have a class with several attributes that saves weekdays with numeric values.
summary_weekday :integer
collection_weekday :integer
In case people are still looking for a solution for Rails 4, I just tried this the other day and it seems to work well. I need a similar system to work because of various checks an admin must do on an object. I solved it by creating a Model Concern and using the class method in the Model:
In models/concerns/review_states.rb
require 'active_support/concern'
module ReviewStates extend ActiveSupport::Concern
class_methods do
REVIEW_STATES = {not_initiated:0, in_progress:1, completed:2}
SIGNUP_STATES = {pending:0, activated:1, disabled:2}
def prefix_review_states(prefix)
Hash[REVIEW_STATES.map { |k,v| [k.to_s.prepend(prefix).to_sym, v] }]
end
end
end
In your model:
class ModelName < ActiveRecord::Base
include ReviewStates
enum one_status: prefix_review_states("one_")
enum two_status: prefix_review_states("two_")
This seems to make all of the correct database queries.
Good luck!