Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails - How to organize constants

I am having some constants that I want to define globally in my applications. Also, these constants don't belong to any model. What's the best practice to organize those constants.

Any advice is highly appreciated

like image 221
quyetdc Avatar asked Jan 18 '26 07:01

quyetdc


1 Answers

simple you can define Module called as example Constants and define it inside the module

module Constants
  CONST1="value"
  CONST2="value2"
end

it's possible also to group them like

 module Constants
  module Group1
    CONST1="value"
    CONST2="value2"
  end
  module Group2
   # some relevant constants 
  end 
end
like image 110
M.Elkady Avatar answered Jan 20 '26 01:01

M.Elkady



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!