0
@@ -18,7 +18,7 @@ This will create a config/settings folder and a blank settings file for each of
0
Now, if you open up the configuration.rb initializer, you will see something like this:
0
-<
filter:jscode lang="ruby">
0
+<
pre><code class="ruby">
0
SimpleConfig.for :application do
0
# your app configuration here
0
@@ -27,7 +27,7 @@ SimpleConfig.for :application do
0
load File.join(RAILS_ROOT, 'config', "settings", "local.rb"), :if_exists? => true
0
This is where you can set any configuration variables that are required across all Rails environments. The <code>load</code> method works just like Ruby's built-in load method, except the contents of the file it loads are evaluated within the context of the <code>SimpleConfig.for</code> block. The <code>:if_exists?</code> flag, when set to true, means that the file will only be loaded if it exists, otherwise it will simply be ignored.
0
@@ -39,21 +39,21 @@ h3. Setting variables
0
Setting variables is simple and will be familiar to anybody who has used Capistrano. Whether in your main <code>SimpleConfig.for</code> block in configuration.rb, or one of your external settings files, use the <code>set</code> method:
0
-<
filter:jscode lang="ruby">
0
+<
pre><code class="ruby">
0
SimpleConfig.for :application do
0
set :my_variable, 'hello world'
0
SimpleConfig also supports a form of namespacing that allows you to group logical sets of variables together:
0
-<
filter:jscode lang="ruby">
0
+<
pre><code class="ruby">
0
SimpleConfig.for :application do
0
group :awesome_stuff do
0
set :my_variable, 'hello world'
0
Both the <code>set</code> and <code>load</code> methods are available within <code>group</code> blocks and files loaded inside groups will be evaluated in the context of that group.
0
@@ -67,17 +67,17 @@ It is worth pointing out that <code>SimpleConfig.for</code> provides an almost s
0
Once you have a reference to your configuration object, you can access variables using method access. Given the above example, <code>:my_variable</code> would be accessed in the following way:
0
-<
filter:jscode lang="ruby">
0
+<
pre><code class="ruby">
0
config = SimpleConfig.for(:application)
0
config.my_variable # => "hello world"
0
Accessing grouped variables works as you would expect:
0
-<
filter:jscode lang="ruby">
0
+<
pre><code class="ruby">
0
config = SimpleConfig.for(:application)
0
config.awesome_stuff.my_variable # => "hello world"
0
h3. Using your configuration in your Rails app
0
@@ -87,29 +87,29 @@ Note - there is no direct way of accessing your configuration variables in your
0
To use the mixin, simply include it in your ApplicationController:
0
-<
filter:jscode lang="ruby">
0
+<
pre><code class="ruby">
0
class ApplicationController < ActionController::Base
0
include SimpleConfig::ControllerMixin
0
Then in your controllers:
0
-<
filter:jscode lang="ruby">
0
+<
pre><code class="ruby">
0
class MyController < ApplicationController
0
render :text => config.my_config_variable
0
fn1(footnote). SimpleConfig was designed with Rails 2.0 in mind but it has been tested with Rails 1.2. To use the Rails-style initializers that SimpleConfig takes advantage of in Rails 1.2, simply add this to the bottom of your environment.rb file:
0
-<
filter:jscode lang="ruby">
0
+<
pre><code class="ruby">
0
# backported Rails 2.x initializer folder functionality
0
Dir[File.join(RAILS_ROOT, 'config', 'initializers', '*.rb')].each do |initializer|
0
fn2(footnote). In fact, I recommend you make sure your version control system ignores this file otherwise you risk checking in a file that will override values in production! If you are using Subversion, simply add local.rb to the svn:ignore property for the config/settings folder.
0
\ No newline at end of file
Comments
No one has commented yet.