Ruby on Rails: Where to define global constants?

前端 未结 12 1760
我在风中等你
我在风中等你 2020-11-28 00:44

I\'m just getting started with my first Ruby on Rails webapp. I\'ve got a bunch of different models, views, controllers, and so on.

I\'m wanting to find a good plac

12条回答
  •  执笔经年
    2020-11-28 01:10

    A common place to put application-wide global constants is inside config/application.

    module MyApp
      FOO ||= ENV.fetch('FOO', nil)
      BAR ||= %w(one two three)
    
      class Application < Rails::Application
        config.foo_bar = :baz
      end
    end
    

提交回复
热议问题