I have written constant.rb in lib/ folder for my rails app.To use that in ActiveRecord, I have written ActiveRecord::Base.extends Constant in constant.rb and it is working. But I don’t know how to use the same in ActionController, I tried ActionController::Base.extends Constant But It is not worked. Pls help.
I have written constant.rb in lib/ folder for my rails app.To use that in
Share
it’s typo… you wrote the plural but actually it’s singular
extend.A few tips:
Constant may not be a good name for your Module maybe call more specific like AppConstant.
You shouldn’t put this into your
lib/constant.rb, it’s cleaner to create a new initializer likeconfig/initializers/constants.rb
maybe there’s an even better way: put the
extend AppConstantinto yourapp/controllers/application_controller.rb