Share enum declaration values with multiple attributes

As of Rails 5.0 you can use the _prefix or _suffix options when you need to define multiple enums with same values. If the passed value is true, the methods are prefixed/suffixed with the name of the enum.

class Invoice < ActiveRecord::Base
  enum verification: [:done, :fail], _prefix: true
end

It is also possible to supply a custom prefix.

class Invoice < ActiveRecord::Base
  enum verification: [:done, :fail], _prefix: :verification_status
end

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)