Show available rake tasks
rake -T
Related cards:
Adjust cron jobs to allow full backtraces for rake tasks
As we get an exception notification, when a cron job fails, we wish to have the full backtrace in this mail. A rake task doesn't output the full backtrace by default, so you need the --backtrace
option.
Trigger
You will find fail mails wit...
Airbrake notification in Rake tasks
Put
def task_with_hoptoad_notification(options)
task(options) do
begin
yield
rescue Exception => e
Airbrake.notify(e)
raise e
end
end
end
at the top of the Rakefile, and r...
Rails logs are not flushed automatically (in Rake tasks)
The Rails logger will store its content in a buffer and write it into the file system every 1000 lines. This will come back to bite you when using Rails.logger.info
to write log output during Rake tasks or on a production console.
You often won...
Modifying Rake Tasks - Dan Manges's Blog
For custom Rake tasks, you shouldn't need to modify them after the original definition. However, if you want to add behavior to some vendor tasks (such as those defined with Rails), this blog post will cover how to do that.
Some nifty Rails Rake tasks
Did you know?
rake stats # => LOC per controllers, models, helpers; code ratios, and more
rake notes # => collects TODO, FIXME and other Tags from comments and displays them
rake about # (Rails 3+) => Rails, Ruby, Rake, Rack etc. vers...
When Rails does not recognize Rake tasks in lib/tasks
When you put a Rake task into lib/tasks
, but running it fails with...
Don't know how to build task name:of:task
... does your Rake task's filename end in .rb
? It needs to end in .rake
instead.
When RubyMine doesn't show you Git blames / annotate gutter not available
- You probably haven't configured version control for your project.
- Go to Project Settings / Version Control and set the director
<Project>
toGit
Make "rake notes" learn about Haml, Sass, CoffeeScript, and other file types
Rails comes with a Rake task notes
that shows code comments that start with "TODO", "FIXME", or "OPTIMIZE".
While it's generally not good practice to leave them in your cod...
Hide a Rake task from the `rake -T` list
A Rake task appears in rake -T
if it has a description:
desc 'Compile assets'
task :compile do
...
end
To not list it, simply omit the description:
task :compile do
...
end
You can also hide a Rake task that has been defi...
Maintaining custom application tasks in Rails
Here are some hints on best practices to maintain your tasks in larger projects.
Rake Tasks vs. Scripts
- The Rails default is using rake tasks for your application tasks. These live in
lib/tasks/*
. - In case you want to avoid rake for your...