I use ActiveRecord Enum to store weekdays with the following:
enum weekday: %w(monday tuesday wednesday thursday friday saturday sunday)
When calling the attribute .weekdayin the model instance, I correctly get the name of the day of the week, for example. "Monday".
.weekday
How can I get a numerical value (i.e. 0) when I need it?
0
Use my_object[:weekday], or, if you are in the facility, simple self[:weekday].
my_object[:weekday]
self[:weekday]
UPDATE: OR (as found by Ms numbers): .read_attribute_before_type_cast(:weekday)
.read_attribute_before_type_cast(:weekday)
What you would like to do is the following:
model_instance.read_attribute(:weekday)
, , .
Source: https://habr.com/ru/post/1538480/More articles:How to match many-to-many relationships in OrientDB - javaМожно ли использовать как старый, так и новый синтаксис flexbox для более широкой совместимости? - cssWhat does SynchronizationContext execute Task.ContinueWith to use? - .netWhy does Rust have mutexes and other sychronization primitives if sharing mutable state between tasks is not allowed? - rustHow to disable property auto-sync property in Xcode 5? - iosHow to programmatically determine if a Windows 8.1 update is installed - c #Secure web API with form authentication (authorization) and basic authentication (message handler) together - authenticationDjango: block internet connection for testing - pythonPygame Level / Menu Creation - pythonSelect an element from a stream with a uniform distributed probability - algorithmAll Articles