开发者

sharing constant between models

开发者 https://www.devze.com 2023-03-16 12:00 出处:网络
I want to have constat defined in two models, but I don\'t want to repeat code. I\'ve placed this constant in config/application.rb开发者_StackOverflow社区. Is that a good practice? Is there a better

I want to have constat defined in two models, but I don't want to repeat code. I've placed this constant in config/application.rb开发者_StackOverflow社区. Is that a good practice? Is there a better way to do that?


A better place to declare application constants would be in a .rb file in config/initializers folder. Declaring a constant in an initializer (or as you have done in config/application.rb) makes it available in ALL models/controllers/views in your application.

0

精彩评论

暂无评论...
验证码 换一张
取 消