Best place to store model specific constants in rails 3.1?

后端 未结 4 983
遥遥无期
遥遥无期 2021-01-31 04:54

I have a field type in a model called user which is an int in the db. The value of the int speficies the type of store it is. Example:

4条回答
  •  后悔当初
    2021-01-31 05:25

    One way you be to write an file in initializers folder or lib folder

    say app_contants.rb and in this file you can write

    MOM=1
    
    DAD=2
    
    1. Incase you write a initializer you can do

    user.type == mom

    2.If you create an lib file make it a module

     module app_constants
        mom = 1
        dad = 2
      end 
    

    and simply include this module wherever you need

提交回复
热议问题