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} 

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.