Friday, December 14, 2007

All About Rake

A build tool helps you build, compile, or other wise process files, sometimes large numbers of them. Rake is a build tool like make ( and Apache ant (, but it is written in Ruby. It is used by Ruby many applications, not just Rails. Rails operations use Rake frequently.

Rake uses a Rake file to figureout what to do . A Rake file contains named tasks.When you create a Rails project, a Rake- file is automatically created to help you deal with a variety of jobs, such as running tests and looking at project statistics. (After creating a Rails project, while in the main Rails project directory,run rake --tasks or rails stats to get a flavor of what Rake does.)

Rake was written by JimWeirich ( You’ll find documentation on Rake at Additionally, you’ll find a good introduction to Rake, by Martin Fowler, at

Check to see whether Rake is present:
$ rake --version

rake, version 0.7.2

If this command fails, use RubyGems to install Rake, as shown in the previous section.

To run Rake help, type:
$ rake --help


rake [-f rakefile] {options} targets...


--classic-namespace (-C)
Put Task and File Task in the top-level namespace.

--dry-run (-n)
Do a dry run without executing actions.

--help (-H)
Display this help message.

--libdir=LIBDIR (-I)
Include LIBDIR in the search path for required modules.

--nosearch (-N)
Do not search parent directories for the Rakefile.

--prereqs (-P)
Display the tasks and dependencies, then exit.

--quiet (-q)
Do not log messages to standard output.

--rakefile (-f)
UseFILE as the Rakefile.

--rakelibdir=RAKELIBDIR (-R)
Auto-import any .rake files in RAKELIBDIR (default is rakelib).

--require=MODULE (-r)
Require MODULE before executing Rakefile.

--silent (-s)
Like --quiet, but also suppresses the in directory announcement.

--tasks (-T)
Display the tasks (matching optional PATTERN) with descriptions, then exit.

--trace (-t)
Turn on invoke/execute tracing; enable full backtrace.

--usage (-h)
Display usage.

--verbose (-v)
Log message to standard output (default).

--version (-V)
Display the program version.

HTTP Basic Authentication using Rails

configure your Rails application to send email messages

Add the following code to config/environment.rb:

ActionMailer::Base.server_settings = {
:address => "",
:port => 25,
:domain => "",
:authentication => :login,
:user_name => "username",
:password => "password"

Replace each hash value with proper settings for your Simple Mail Transfer Protocol (SMTP) server.

You may also change the default email message format. If you prefer to send email in HTML instead of plain text format, add the following line to config/environment.rb as well:

ActionMailer::Base.default_content_type = "text/html"

Possible values for ActionMailer::Base.default_content_type are "text/plain", "text/html", and "text/enriched". The default value is "text/plain".