Enums Emulation In Ruby
Join the DZone community and get the full member experience.
Join For FreeType = [V1 = 'v1', V2 = 'v2']
class EntryForm
include ActiveModel::Validation
Remind = [Periodically = 'periodically', Once = 'once', Never = 'never']
validate_inclusion_of :remind, :in => Remind
before_save {
if @remind == Periodically
self.schedule_yaml = create_schedule(...).to_yaml
...
}
...
end
_form.html.haml:
...
f.select :remind, EntryForm::Remind
...
Opinions expressed by DZone contributors are their own.
Comments