J B
J B

Reputation: 400

Rails 4 custom initializer configuration variables

How can I add custom configuration variables in an initializer in Rails 4? I've tried a simple test in config/initializers/stuff.rb

Rails.application.config.stuff = 'foo'

based on the "Custom Configuration" section of this Rails Guide: http://guides.rubyonrails.org/configuring.html

I know I can add these to config/application.rb, the environments files, etc., but is there a way to make this work properly in an initializer? When I attempt to view this variable in the console, it's not there. I also do not receive any errors. Do I need a special block? Other initializers from various applications have what I have above and their configurations show up. Example from assets.rb:

Rails.application.config.assets.version = '1.0'

Upvotes: 0

Views: 1305

Answers (1)

J B
J B

Reputation: 400

It appears that it does work; the problem is that pry is not autocompleting these variables, even with

Rails.application.eager_load!

set in .pryrc, and I'm not sure why that is.

Upvotes: 0

Related Questions