0

I'm using my config/environments/<env>.rb files to set custom configuration variables (see https://stackoverflow.com/a/5053882/483520). For example, I might set the following:

config.google_analytics_on = false #or true, in a production environment
config.google_analytics_account = "<account-string>"

It would be nice to be able to do:

config.google_analytics.on = false
config.google_analytics.account = "<account-string>"

so that all my google_analytics variables would be under that scope. However, rails complains about config.google_analytics not being defined. How do I create it?

Community
  • 1
  • 1
Nolan Amy
  • 10,785
  • 5
  • 34
  • 45

1 Answers1

2
opts = {on: false, account: "<account-string>"}
config.google_analytics = OpenStruct.new(opts)
Mori
  • 27,279
  • 10
  • 68
  • 73
  • Can I do something with a syntax more like: `config.google_analytics = OpenStruct.new` `config.google_analytics.on = false` `config.google_analytics.account = ""` EDIT: Indeed: http://www.ruby-doc.org/stdlib-1.9.3/libdoc/ostruct/rdoc/OpenStruct.html – Nolan Amy Jul 21 '12 at 18:10