0

Yesterday I asked a quiostion about Rails 4 Enum and got answer.

So I have defined global Status enum in #app/models/concerns/my_enums.rb like this:

module MyEnums
  extend ActiveSupport::Concern

  included do
    enum status: [:active, :inactive, :deleted]
  end
end

Now im trying to get all defined properties in my Status enum from controller, cannot access enum because it initializes when module included and if i include it in my controller I`ll get this error:

undefined method `enum' for HomeController:Class

How can I get this in my controller(like Product.statuses)?

=> {"active"=>0, "inactive"=>1, "deleted"=>2} 
Community
  • 1
  • 1
Irakli Lekishvili
  • 33,492
  • 33
  • 111
  • 169

1 Answers1

1

You cannot include this module into your controller. You could however try:

module MyEnums
  extend ActiveSupport::Concern
  Statuses = [:active, :inactive, :deleted]

  included do
    enum status: Statuses
  end

end

And then in the controller:

MyEnums::Statuses
BroiSatse
  • 44,031
  • 8
  • 61
  • 86