Search code examples
ruby-on-railsyamlenumerize

How to access YML file in rails


I have set up a settings.yml file in my config folder with some list elements I want to pass to my enumerize in my rails model :

config/ settings.yml
enumerize:
  hotel_status:
    - "Hotel Privé"
    - "Bâtiment Publique"
    - "CHRS"
    - "CADA"
    - "Centre d'accueil"
    - "Camping"
    - "Autres"

I am trying to pass the list inside my Hotel model to enumerize this way :

  enumerize :status, in: Settings.enumerize.hotel_status

but I am getting uninitialized constant Hotel::Settings

How can I pass the list in the YML to enumerize.


Solution

  • There is a gem called config, you can do it without hassle plus you can add multi-environment settings to your app.