Accessing config from application.rb in Controller (Rails 3)

前端 未结 5 1171
情书的邮戳
情书的邮戳 2020-12-23 10:47

I\'m trying to add two extra config options to my application.rb so I can read them out in controllers.

# Extra
config.twitter.key = \'foo\'
config.twitter.s         


        
5条回答
  •  情深已故
    2020-12-23 11:11

    I've tried this and seems to be working, you can use ::Rails.application.config.

    For example I'm using it to get the correct time_zone set in the application like this:

    Rails.application.config.time_zone

    I found it thanks to the less-rails code: https://github.com/metaskills/less-rails/blob/master/lib/less/rails/helpers.rb

    So you can declare this in your application.rb or in any enviroment file:

    config.twitter_key = 'foo'

    And then read it like so anywhere in your code:

    Rails.application.config.twitter_key

提交回复
热议问题