Definitive guide to Rake commands

If I want to look up the available Rake command syntax, where do I go to
find it?

For example, if I want to look up the syntax of a Rails command I can
find it at:

http://api.rubyonrails.com

I can even look up the core Rake api at:

http://rake.rubyforge.org/

What I can’t find is documentation of indivdual core Rails Rake tasks.

For example, I’ve been trying to find out if there is a better way for
me to use the rake db:migration task. I’ve always used

rake environment RAILS_ENV=production db:migrate

to migrate my production database and that always seems verbose to me.
However, as I can’t find an api or other document (or even where the
code that is run when you run the db:migration task), I have to rely on
google searches to see what other people are using.

Can someone please point me in the right direction.

On Wed, Oct 7, 2009 at 11:50 AM, Rob N.
[email protected] wrote:

If I want to look up the available Rake command syntax, where do I go to
find it?

rake -T


Greg D.
http://destiney.com/

If I want to look up the available Rake command syntax, where do I
go to
find it?

$ rake -T

http://guides.rubyonrails.org/command_line.html#rake-is-ruby-make

vendor/rails/railties/lib/tasks/*.rake

google searches to see what other people are using.
That’s about as good as it’s gonna get. Depending on the shell you can
do

RAILS_ENV=production rake db:migrate

Not a whole heck of a lot shorter though.

Thank you Greg and Philip

$ rake -T

rake -T lists the available commands. It doesn’t give you any syntax for
each command. Specifically, it doesn’t list the available parameters and
switches. For example, it doesn’t specify that you can use the keyword
‘environment’ with db:migrate.

http://guides.rubyonrails.org/command_line.html#rake-is-ruby-make

Again another list of the rake tasks - but not the avaiable options for
each task.

vendor/rails/railties/lib/tasks/*.rake

That’s has led me down a useful path.

I’ve found the location of the standard Rails rake commands. On a
Windows system running Rails 2.3.4 they are at:

/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/tasks

Specifically the code controlling db:migrate is in database.rake (I’d
been searching for a file with ‘migrate’ or ‘migration’ in the file
name). I should be able to work through this source code and work out
the command syntax.

RAILS_ENV=production rake db:migrate

Not a whole heck of a lot shorter though.

I might see if I can modify mine to:

rake db:migrate production

Thank you for your replies

Rob N. wrote:

RAILS_ENV=production rake db:migrate

That doesn’t work on my system, but this does

rake db:migrate RAILS_ENV=production

Which is better than what I had. It looks like you don’t need the
‘environment’ key word.

I might see if I can modify mine to:

rake db:migrate production

Looking at this closer, this isn’t too clever an idea once you start
wanting to roll backwards and forwards through versions. The more I look
at it, the more “rake db:migrate RAILS_ENV=production” looks fine.

On Wed, Oct 7, 2009 at 9:50 AM, Rob N. <
[email protected]> wrote:

http://rake.rubyforge.org/

What I can’t find is documentation of indivdual core Rails Rake tasks.

You can read the source of the core rake tasks by doing the following:

a) locate the gem directory for your ruby implementation
b) navigate into the rails-2../lib/tasks

 Note:  The file that you're looking for end in the .rake extension.

For example, I’ve been trying to find out if there is a better way for
me to use the rake db:migration task. I’ve always used

rake environment RAILS_ENV=production db:migrate

You can write the above as

rake db:migrate RAILS_ENV=production

Also, you can add a task to your Rails Rakefile and simplify it by doing
something
like this

rake db:migrate:production

Next, I would recommend reading code because the API may not provide
the complete picture at this time. Also, there are so many examples of
how
to create a rake task and here’s a tutorial here:

http://railscasts.com/episodes/66-custom-rake-tasks

to migrate my production database and that always seems verbose to me.

However, as I can’t find an api or other document (or even where the
code that is run when you run the db:migration task), I have to rely on
google searches to see what other people are using.

Can someone please point me in the right direction.

Next, Rake is simply a gem that is used by Rails. Thus, you can find
the documentation for Rake here and it took a simple Google search:

http://rake.rubyforge.org

If you search for it, you’ll find it.

Good look,

-Conrad

Thank you Conrad. That was very helpful. Particularly the path to the
rake files and link to the turorial.

Conrad T. wrote:

Next, Rake is simply a gem that is used by Rails. Thus, you can find
the documentation for Rake here and it took a simple Google search:

http://rake.rubyforge.org

If you search for it, you’ll find it.

I had found this and mentioned it in my original posting. My problem was
that the rake api told me how rake worked, but not how individual rake
tasks such as rake db:migrate worked. It seems the only way to find this
out is to dig into the code (which at the time of writing, I’d failed to
locate).

I guess what I’m missing is an rdoc equivalent for rake tasks. It looks
like there has been some thoughts along these lines as Rake has a
display_tasks_and_comments method (which I think is used by ‘rake -T’).
However the output is very basic and describes what the task does but
not how to use it.

Perhaps I’ve been spoilt by api.rubyonrails.com. Its a shame that the
rake tasks that are core to Rails, aren’t as well documented.

Thank you again Conrad.

I have answered the question that started me down this path. That was,
is there a simpler form of rake db:migrate that I could use to migrate
non-development databases.

However, the reason I posted here was because I thought I may have
missed a resource somewhere that would allow me to both answer my
immediate query, and more importantly make it easier to answer future
rake related queries.

The consequence of me posting here is that I seem to have confirmed that
there is no centrally managed resource where I can go to look up the
syntax usage of Rails core Rake tasks such as db:migrate. However, from
this thread I have learnt where the rake task source code resides and
that I can use this to interpret how to use these rake tasks.

So as far as I am concerned, I think this thread is closed.

On Thu, Oct 8, 2009 at 2:42 AM, Rob N. <
[email protected]> wrote:

If you search for it, you’ll find it.

I had found this and mentioned it in my original posting. My problem was
that the rake api told me how rake worked, but not how individual rake
tasks such as rake db:migrate worked. It seems the only way to find this
out is to dig into the code (which at the time of writing, I’d failed to
locate).

If you’re interested in the rake task db:migrate, you can do a search
for
the
following file:

databases.rake

I guess what I’m missing is an rdoc equivalent for rake tasks. It looks
like there has been some thoughts along these lines as Rake has a
display_tasks_and_comments method (which I think is used by ‘rake -T’).
However the output is very basic and describes what the task does but
not how to use it.

Did you read the following document:

http://rake.rubyforge.org/files/doc/rakefile_rdoc.html

Perhaps I’ve been spoilt by api.rubyonrails.com. Its a shame that the
rake tasks that are core to Rails, aren’t as well documented.

What are you trying to do? Perhaps more information from you can allow
us to better assist you.

-Conrad

Rob N. wrote:

Thank you again Conrad.

I have answered the question that started me down this path. That was,
is there a simpler form of rake db:migrate that I could use to migrate
non-development databases.

Rake db:migrate, like most railsy things, looks at the RAILS_ENV
environment variable to determine which environment to work on. You can
set that any way you like. Youbcan even write a new Rake task to set it
for you.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs