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.

rake -T

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

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.

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.

Rob Nichols 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.

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.

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 Taylor 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 Conrad. That was very helpful. Particularly the path to the

rake files and link to the turorial.

Conrad Taylor 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).

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

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.