Ruby on Rails: get variable from include do -
yesterday asked quiostion rails 4 enum , got answer.
so have defined global status
enum in #app/models/concerns/my_enums.rb
this:
module myenums extend activesupport::concern included enum status: [:active, :inactive, :deleted] end end
now im trying defined properties in status
enum controller, cannot access enum because initializes when module included , if include in controller i`ll error:
undefined method `enum' homecontroller:class
how can in controller(like product.statuses)?
=> {"active"=>0, "inactive"=>1, "deleted"=>2}
you cannot include module controller. try:
module myenums extend activesupport::concern statuses = [:active, :inactive, :deleted] included enum status: statuses end end
and in controller:
myenums::statuses
Comments
Post a Comment