Both objects seem to be nil inside of 'rails console'.
Why is that?
Actually now Rails works:
puts Rails.env
/path/to/my/project
but for config:
puts config.root
NameError: undefined local variable or method `config' for #<Object:0x1001dd2a0>
from (irb):8
Keeping Environment Variables PrivateRemote git repositories such as GitHub are a place to store and share code. If your project is open source, any developer will have access to your code. You don't want to share email account credentials or private API keys with the public.
In general, the work of configuring Rails means configuring the components of Rails, as well as configuring Rails itself. The configuration file config/application. rb and environment-specific configuration files (such as config/environments/production.
You probably know that you can configure Rails in config/application. rb and config/environments/development. rb etc. But you can also leverage that for configuring your own custom settings for your application.
The Rails environment is determined by whatever the value of the RAILS_ENV environment variable is when the server starts. You might have some configuration file somewhere that specifies it, or maybe you just start your server with a command of the form RAILS_ENV=production my_rails_server ?
There is no global config
method. If you're copying this from your environment files in Rails 2, note that these are actually evaluated within a certain context.
To get to the config
object from your console, try one of the following:
For Rails 3 and above:
Rails.application.config
For Rails 2.x:
Rails.configuration
If you need to get your project's root directory (not sure if this is actually what you're trying to accomplish), you can do the following in Rails 2 and above:
Rails.root
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With