Deprecated: Return type of Requests_Cookie_Jar::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/local/www/vhosts/jasonnoble.org/htdocs/wordpress/wp-includes/Requests/Cookie/Jar.php on line 63

Deprecated: Return type of Requests_Cookie_Jar::offsetGet($key) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/local/www/vhosts/jasonnoble.org/htdocs/wordpress/wp-includes/Requests/Cookie/Jar.php on line 73

Deprecated: Return type of Requests_Cookie_Jar::offsetSet($key, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/local/www/vhosts/jasonnoble.org/htdocs/wordpress/wp-includes/Requests/Cookie/Jar.php on line 89

Deprecated: Return type of Requests_Cookie_Jar::offsetUnset($key) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/local/www/vhosts/jasonnoble.org/htdocs/wordpress/wp-includes/Requests/Cookie/Jar.php on line 102

Deprecated: Return type of Requests_Cookie_Jar::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/local/www/vhosts/jasonnoble.org/htdocs/wordpress/wp-includes/Requests/Cookie/Jar.php on line 111

Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/local/www/vhosts/jasonnoble.org/htdocs/wordpress/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 40

Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::offsetGet($key) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/local/www/vhosts/jasonnoble.org/htdocs/wordpress/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 51

Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::offsetSet($key, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/local/www/vhosts/jasonnoble.org/htdocs/wordpress/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 68

Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::offsetUnset($key) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/local/www/vhosts/jasonnoble.org/htdocs/wordpress/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 82

Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/local/www/vhosts/jasonnoble.org/htdocs/wordpress/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 91
Updated: Rails3 Custom Environment Variables – Jason Noble's Technical Adventures

Updated: Rails3 Custom Environment Variables

Posted by Jason Noble on 12/03/2011 in ruby on rails |

A while back, I wrote a blog post on adding custom environment variables to Rails3.

This has gotten much easier with a change made by Jose Valim back in March.

The change allows you to create your own custom configuration variables like so:

[ruby]
# config/environments/development.rb
Demo::Application.configure do
[…]
config.json_url = "http://www.domain.com"
[…]
end
[/ruby]

[ruby]
# config/environments/test.rb
Demo::Application.configure do
[…]
config.json_url = "http://test.domain.com"
[…]
end
[/ruby]

This allows you to add any configuration variables you want to your Rails app. What if you have a bunch of configuration values? You don’t want to pollute your config.* namespace. Wouldn’t it be helpful to have config.my_app.json_url and config.my_app.other_url?

That’s easy enough:

[ruby]
# config/environments/application.rb
Demo::Application.configure do
config.my_app = ActiveSupport::OrderedOptions.new
end
[/ruby]

[ruby]
# config/environments/development.rb
Demo::Application.configure do
[…]
config.my_app.json_url = "http://www.domain.com"
[…]
end
[/ruby]

[ruby]
# config/environments/test.rb
Demo::Application.configure do
[…]
config.my_app.json_url = "http://test.domain.com"
[…]
end
[/ruby]

Now you can do the following in the Rails console:

[ruby]
$ rails console
>> Demo::Application.config.my_app.json_url
"http://www.domain.com"
>>
[/ruby]

[ruby]
$ rails console test
>> Demo::Application.config.my_app.json_url
"http://test.domain.com"
>>
[/ruby]

Now your Rails application will have access to all the configuration you need.

Copyright © 2008-2023 Jason Noble's Technical Adventures All rights reserved.
This site is using the Desk Mess Mirrored theme, v2.5, from BuyNowShop.com.