3. Railties
3.1 New Environment
config/environments/production.rb
config/environments/development.rb
config/environments/test.rb
The default environment is now development and contains the new automatic
dependency reloading.
3.2 RAILS_ENV system
Since the default environment is now development we introduced a ENV system variable to choose which rails environment to choose. The reason behind this is that you can now use the same source code on your production side and on your develop machine. If you use webrick on your production machine you can tell it to run in production mode using the -e parameter
/script/server -e production -i mystartupcontroller
if you use CGI or mod_ruby you can use the apache SetEnv directive either server wide or in your virtual server subgroup
SetEnv RAILS_ENV production
Fastcgi needs some extra treatment since ENV variables are not passed on to FastCGI childrens at startup. Here is a working server wide example:
FastCgiConfig -initial-env RAILS_ENV=production -restart
Alternatively you can set it only for a certain application like this:
FastCgiServer /var/www/applications/myapp/public/dispatch.fcgi -initial-env RAILS_ENV=production
3.3 Breakpoints
class WeblogController < ActionController::Base
def index
@posts = Post.find_all
breakpoint "Breaking out from the list"
end
end
So the controller will accept the action, run the first line, then present you with a IRB prompt in the breakpointer window.
Here you can do things like:
Executing breakpoint "Breaking out from the list" at .../webrick_server.rb:16 in 'breakpoint'
>> @posts.inspect
=> "[#<Post:0x14a6be8 @attributes={\"title\"=>nil, \"body\"=>nil, \"id\"=>\"1\"}>,
#<Post:0x14a6620 @attributes={\"title\"=>\"Rails you know!\", \"body\"=>\"Only ten..\", \"id\"=>\"2\"}>]"
>> @posts.first.title = "hello from a breakpoint"
=> "hello from a breakpoint"
...and even better is that you can examine how your runtime objects actually work:
>> f = @posts.first
=> #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
>> f.
Display all 152 possibilities? (y or n)
Finally, when you’re ready to resume execution, you press CTRL-D
3.4 Setting Default Session Options
Default session options can now be set in config/environment.rb or even in a specific environment in config/environments/.
As an example, to set a custom prefix you would add the following to config/environment.rb:
ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.update(:prefix => 'my_prefix.')