I am implementing multiple select elements in my view and wanted to use 
enum method to have a clean implementation and control over values for 
select tag.
Then, I started writing this in my model.

FONTS = {
    "Arial": 0,
    "Courier New": 1,
    "Garamond": 2,
    "Georgia": 3,
    "Helvetica": 4,
    "Impact": 5,
    "Lucida Console": 6,
    "Lucida Grande": 7,
    "Monaco": 8,
    "Palatino": 9,
    "Times New Roman": 10,
    "Trebuchet MS": 11
  }

  enum header_font: FONTS
  enum text_font: FONTS

Soon after I got the error "but this will generate a instance method 
"Arial?", which is already defined by another enum."

I understand the conflict here but I think enum implementation is really 
neat feature in Rails and should be used more often. ( am i wrong? )

In this scenario, I was never going to use Model.arial?  method. The only 
reason for using enums here was to use, for example these methods;  

Model.header_fonts
Model.text_fonts
validates_inclusion_of :header_fonts, in: Model.header_fonts.keys


Do you think that there should be an option to initialize an enum without 
helpers ?

Something like

enum header_font: FONTS, helpers: false

Or should I just use constants instead?

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

Reply via email to