Prev | Current Page 464 | Next

Brad Ediger

"Advanced Rails"

inflections do |inflect|
inflect.plural(/(data)$/i, '\1')
inflect.singular(/(data)$/i, '\1')
end
The last trick for initialization is the after_initialize block. Included as part of the
configuration, it will be run at the end of initialization (immediately before the initializers
mentioned previously). The block is specified thus:
config.after_initialize do
# some initialization code...
end
Unfortunately, you only get one after_initialize block per initialization??”you can??™t
have one in environment.rb and another in production.rb. So, choose wisely where
you need it. My recommendation: use it in your environment-specific configuration
files, and use the initializers directory for your generic initialization.
Including Gems
When deploying to a new machine, it can be frustrating to make sure all of the
dependencies are in order. RubyGems are typically the main culprit here. One way to
ensure you have gem dependencies under your control is to include them in the
project tree. This idea, from Chris Wanstrath,* is the natural extension of keeping
Rails and plugins within the project.
To include gems in the project, we will create a directory to hold them, then unpack
a gem there using the gem unpack command (you may need to update RubyGems for
this command to work):
$ mkdir vendor/gems
$ cd vendor/gems
$ gem unpack hpricot
Unpacked gem: 'hpricot-0.4'
Now we need to ensure that the directory we have created is added to the load path.


Pages:
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476