This article explains the basics of Rake. It’s a super popular build tool that is written in Ruby. It offers a lot of flexibility and is used to manage all kinds of tasks. If you are using Rails, I recommend taking a look under the hood to find out what tasks are at your disposal and how to write your own.
Topics
- What Is Rake?
- Task List
- Getting Started
- Namespaces
- Prerequisites
- Passing Arguments
- Tasks of Interest
What Is Rake?
Thanks to Rails, Rake has become a de facto standard as a Ruby build tool. It’s super popular in the Ruby community. Very early, the team behind Rails decided to use Rake as the builder for Rails itself, which meant that in the past when you downloaded Rails, you also needed a copy of Rake. That way it exposed Rake to a lot of people. A little later, it was included into Ruby (1.9) itself.
Rake de facto replaced the Unix utility Make as a build tool in Ruby land. A build tool like Rake is handy for automating tasks of various kinds—a software for managing tasks basically. It is often used for administration tasks in Rails—which is where you most likely have run into it so far—but its use cases are plenty. Some people write their ebooks in Markdown and have set up Rake tasks that convert the relevant files to intermediate HTML files, which then in turn get converted into ebook formats, for example. Saves a lot of trouble to use Rake for that.
What makes Rake really powerful is that these tasks can relate to one another and can be built on top of each other. Also, since it is written in Ruby, you can write any Ruby code for your tasks. Want to use Ruby libraries in your Rake tasks? No problem! Fun fact: it is the most downloaded RubyGem, with over 100 million downloads. So definitely something in your tool belt that you should pay a little more attention to.
It was conceived by the late Jim Weirich, a well-known and beloved developer, speaker and contributor to the Ruby ecosystem. It’s a beautiful tool really—thanks, Jim! RIP!
Task List
Let’s take a look at some tasks that Rails offers right out of the box. I bet you are a bit surprised at what’s available if you haven’t checked before. In the relevant directory of your app or your Rakefile, you can list them by typing the following into a shell:
rake --tasks #or rake -T
Output:
rake about # List versions of all Rails frameworks and the environment rake assets:clean[keep] # Remove old compiled assets rake assets:clobber # Remove compiled assets rake assets:environment # Load asset compile environment rake assets:precompile # Compile all the assets named in config.assets.precompile rake cache_digests:dependencies # Lookup first-level dependencies for TEMPLATE (like messages/show or comm... rake cache_digests:nested_dependencies # Lookup nested dependencies for TEMPLATE (like messages/show or comments/... rake db:create # Creates the database from DATABASE_URL or config/database.yml for the cu... rake db:drop # Drops the database from DATABASE_URL or config/database.yml for the curr... rake db:fixtures:load # Load fixtures into the current environment's database rake db:migrate # Migrate the database (options: VERSION=x, VERBOSE=false, SCOPE=blog) rake db:migrate:status # Display status of migrations rake db:rollback # Rolls the schema back to the previous version (specify steps w/ STEP=n) rake db:schema:cache:clear # Clear a db/schema_cache.dump file rake db:schema:cache:dump # Create a db/schema_cache.dump file rake db:schema:dump # Create a db/schema.rb file that is portable against any DB supported by AR rake db:schema:load # Load a schema.rb file into the database rake db:seed # Load the seed data from db/seeds.rb rake db:setup # Create the database, load the schema, and initialize with the seed data ... rake db:structure:dump # Dump the database structure to db/structure.sql rake db:structure:load # Recreate the databases from the structure.sql file rake db:version # Retrieves the current schema version number rake doc:app # Generate docs for the app -- also available doc:rails, doc:guides (optio... rake log:clear # Truncates all *.log files in log/ to zero bytes (specify which logs with... rake middleware # Prints out your Rack middleware stack rake notes # Enumerate all annotations (use notes:optimize, :fixme, :todo for focus) rake notes:custom # Enumerate a custom annotation, specify with ANNOTATION=CUSTOM rake rails:template # Applies the template supplied by LOCATION=(/path/to/template) or URL rake rails:update # Update configs and some other initially generated files (or use just upd... rake routes # Print out all defined routes in match order, with names rake secret # Generate a cryptographically secure secret key (this is typically used t... rake spec # Run all specs in spec directory (excluding plugin specs) rake spec:controllers # Run the code examples in spec/controllers rake spec:features # Run the code examples in spec/features rake spec:helpers # Run the code examples in spec/helpers rake spec:models # Run the code examples in spec/models rake spec:views # Run the code examples in spec/views rake stats # Report code statistics (KLOCs, etc) from the application or engine rake time:zones:all # Displays all time zones, also available: time:zones:us, time:zones:local... rake tmp:clear # Clear session, cache, and socket files from tmp/ (narrow w/ tmp:sessions... rake tmp:create # Creates tmp directories for sessions, cache, sockets, and pids
The output in a Rails app is surprisingly plentiful, isn’t it? You can find a lot more handy tasks than the usual rake db:migrate
or rake routes
that we are so familiar with and run multiple times on a daily basis.
On the left, you see the various tasks, and on the right, you see what is optionally provided as a description to every rake task. If you want to see the complete list, which among other things also includes tasks that lack a description, you need to add an additional flag.
Shell:
rake -T -A #or rake -T -all
Output:
rake about # List versions of all Rails frameworks and the environment rake assets:clean[keep] # Remove old compiled assets rake assets:clobber # Remove compiled assets rake assets:environment # Load asset compile environment rake assets:precompile # Compile all the assets named in config.assets.precompile rake cache_digests:dependencies # Lookup first-level dependencies for TEMPLATE (like messages/show or comments/_comment.html) rake cache_digests:nested_dependencies # Lookup nested dependencies for TEMPLATE (like messages/show or comments/_comment.html) rake db:_dump # rake db:abort_if_pending_migrations # rake db:charset # rake db:collation # rake db:create # Creates the database from DATABASE_URL or config/database.yml for the current RAILS_ENV (use db:create:all to create all databases in the config) rake db:create:all # rake db:drop # Drops the database from DATABASE_URL or config/database.yml for the current RAILS_ENV (use db:drop:all to drop all databases in the config) rake db:drop:all # rake db:fixtures:identify # rake db:fixtures:load # Load fixtures into the current environment's database rake db:forward # rake db:load_config # rake db:migrate # Migrate the database (options: VERSION=x, VERBOSE=false, SCOPE=blog) rake db:migrate:down # rake db:migrate:redo # rake db:migrate:reset # rake db:migrate:status # Display status of migrations rake db:migrate:up # rake db:purge # rake db:purge:all # rake db:reset # rake db:rollback # Rolls the schema back to the previous version (specify steps w/ STEP=n) rake db:schema:cache:clear # Clear a db/schema_cache.dump file rake db:schema:cache:dump # Create a db/schema_cache.dump file rake db:schema:dump # Create a db/schema.rb file that is portable against any DB supported by AR rake db:schema:load # Load a schema.rb file into the database rake db:schema:load_if_ruby # rake db:seed # Load the seed data from db/seeds.rb rake db:setup # Create the database, load the schema, and initialize with the seed data (use db:reset to also drop the database first) rake db:structure:dump # Dump the database structure to db/structure.sql rake db:structure:load # Recreate the databases from the structure.sql file rake db:structure:load_if_sql # rake db:test:clone # rake db:test:clone_schema # rake db:test:clone_structure # rake db:test:deprecated # rake db:test:load # rake db:test:load_schema # rake db:test:load_structure # rake db:test:prepare # rake db:test:purge # rake db:version # Retrieves the current schema version number rake default # rake doc # rake doc/app # rake doc/app/created.rid # rake doc:app # Generate docs for the app -- also available doc:rails, doc:guides (options: TEMPLATE=/rdoc-template.rb, TITLE="Custom Title") rake doc:clobber # rake doc:clobber_app # rake doc:clobber_rails # rake doc:guides # rake doc:rails # rake doc:reapp # rake doc:rerails # rake environment # rake html # rake html/created.rid # rake log:clear # Truncates all *.log files in log/ to zero bytes (specify which logs with LOGS=test,development) rake magic # Magic rake task rake middleware # Prints out your Rack middleware stack rake no_description # rake notes # Enumerate all annotations (use notes:optimize, :fixme, :todo for focus) rake notes:custom # Enumerate a custom annotation, specify with ANNOTATION=CUSTOM rake notes:fixme # rake notes:optimize # rake notes:todo # rake rails:template # Applies the template supplied by LOCATION=(/path/to/template) or URL rake rails:templates:copy # rake rails:update # Update configs and some other initially generated files (or use just update:configs or update:bin) rake rails:update:bin # rake rails:update:configs # rake railties:install:migrations # rake routes # Print out all defined routes in match order, with names rake secret # Generate a cryptographically secure secret key (this is typically used to generate a secret for cookie sessions) rake spec # Run all specs in spec directory (excluding plugin specs) rake spec:controllers # Run the code examples in spec/controllers rake spec:features # Run the code examples in spec/features rake spec:helpers # Run the code examples in spec/helpers rake spec:models # Run the code examples in spec/models rake spec:prepare # rake spec:statsetup # rake spec:views # Run the code examples in spec/views rake stats # Report code statistics (KLOCs, etc) from the application or engine rake time:zones:all # Displays all time zones, also available: time:zones:us, time:zones:local -- filter with OFFSET parameter, e.g., OFFSET=-6 rake time:zones:local # rake time:zones:us # rake tmp # rake tmp/cache # rake tmp/cache/assets # rake tmp/cache/assets/development # rake tmp/cache/assets/production # rake tmp/cache/assets/test # rake tmp/pids # rake tmp/sessions # rake tmp/sockets # rake tmp:cache:clear # rake tmp:clear # Clear session, cache, and socket files from tmp/ (narrow w/ tmp:sessions:clear, tmp:cache:clear, tmp:sockets:clear) rake tmp:create # Creates tmp directories for sessions, cache, sockets, and pids rake tmp:pids:clear # rake tmp:sessions:clear # rake tmp:sockets:clear #
Surprise, almost three times as much! Take a look at them and play around if you like, but commit the highlights to memory for later usage in the future. Checking the tasks to see what’s available might prevent you from reinventing the wheel.
Getting Started
A Rakefile can have one of the following five appearances:
- rakefile.rb
- rakefile
- Rakefile
- Rakefile.rb
- .rake files
Mostly you will see the plain Rakefile
version, but a framework like Rails needs more complex organization. Use whatever gets your blood flowing. You start by creating a Rakefile
or files with a .rake
extension if you want to split tasks up logically over multiple files. Then define your tasks inside either of them.
Custom Rakefile Organization
Rails makes this incredibly easy. It has a Rakefile in the root of your app. It contains the following:
Rakefile
require File.expand_path('../config/application', __FILE__) Rails.application.load_tasks
When you have a lot of custom tasks, it makes more sense to split them into discrete .rake
files and place them in lib/tasks
. The Rakefile above just loads them, but the lib
directory is a better logical home for the tasks. There is even a Rails generator to automate part of the process. If you type:
Shell
rails generate some_task => create lib/tasks/some_task.rake
You will get a Rakefile placed automatically in the right directory. Even the task is already set up for you. Nice! In other projects, not using Rails, you just need to create a rakelib
directory and place your Rakefiles in there—preferably with .rake
file extensions. Then create a file called Rakefile
and all these files are already at your disposal.
Rake Task Anatomy
lib/tasks/some_task.rake
desc 'List versions of all Rails frameworks and the environment' task :about do puts 'Some magic goes in here…' end
For the complete Ruby newbies among you, and for people coming from bracket-heavy languages, this is how it would look with parentheses.
desc('List versions of all Rails frameworks and the environment') task(:about) do puts('Some magic goes in here…') end
Looks very weird, by the way. Just lose the extra parentheses—nobody writes tasks this way.
We provided a named task :about
with a description that not only reminds us in the future what we wanted to achieve with particular tasks, but also shows up when we run rake -T
. Don’t get lazy on this part; it’s probably not worth it.
Right below is the keyword task that defines a new task named about
. This can be invoked on the command line via rake about
which does its magic then. rake :about
on the other hand will cause Rake to abort, not knowing “how to build task :about”.
Via the do end
block, we have a lambda
, and its body specifies what the task does. This is the basic setup a task will need. It offers a lot more options, of course, but the overall structure is the same.
require / import
Some Rakefile
require './whatever.rb'
If you need to include other Ruby files or Rakefiles, it can easily be achieved by a standard require
statement.
Some Rakefile
import 'whatever.rb'
Rake itself provides us with another way to do this—the import
method. This can be used in any line of the Rakefile. This one will help when you run into trouble because the required file was loaded before the Rakefile finished loading and blew up therefore. The imported file, on the other hand, will always load after the Rakefile.
invoke & execute
Sometimes you might want to execute some defined task from your Task
class manually. For this purpose, you have two methods of the Rake::Task
class: execute
and invoke
.
Rake::Task['some_task'].invoke Rake::Task['some_task'].execute
With the Rake::Task['some_task']
code, we got the some_task
Rake task to execute. It returns an instance of the Rake::Task
class and then runs any method on it that is available.
Namespaces
A very cool feature is the ability to namespace your tasks. You probably have used this dozens of times already. When you run rake db:migrate
, you have made use of the db
namespace, for example. You invoke the task by separating it with a colon :
from the namespace. Namespaces are a handy way to organize your tasks within in a rake file—it keeps them logically separated. Multiple namespaces like rake time:zones:all
are fine, by the way.
Other examples include:
rake db:drop rake db:seed rake log:clear rake spec:views rake spec:models rake db:rollback rake spec:helpers rake spec:features rake db:schema:load rake assets:precompile rake db:migrate:status
Some Rakefile
namespace :db do desc 'Migrating some stuff' task :migrate do ... end end
This is the basic setup. In reality it’s much more complicated and can even be nested multiple times. Have a quick peek at the Rails codebase and see for yourself how rake db:migrate
is implemented. Don’t feel bad if it’s over your head. Just look around, try to discern how it’s structured, and move on for now.
Prerequisites
Another strategy to organize your tasks and to keep them DRY is using prerequisites for executing a task. It’s like a dependency that has to run first before the actual task starts its job. That way you can build up more complex tasks—as complex as you need. But I would recommend not getting too clever and to keep it as simple as possible—and as easy to understand as possible as well.
Some Rakefile
task :stop_megalomaniac do puts 'Lots of smart talk, car chases and guns fired' end task :bond_saves_the_day => :stop_psychotic_megalomaniac do puts 'Lots of Dom Pérignon, oysters and bond girl business' end
If you want to rely on multiple tasks, you just stick them into an array. The order in which you place them matters, of course.
task :get_mr_wolf do puts "You ain’t got no problem Jules, I’m on it! Go in there and chill them out and wait for the wolf who should be coming directly!" end task :figure_out_bonnie_situation do puts "If I was informed correctly, the clock is ticking. Is that right Jimmy?" end task :calm_down_jimmy do puts "Jimmy, do me a favor, will you? I smelled some coffee back there. Would you make me a cup?" end task :get_vince_vega_in_line do puts "Come again? Get it straight buster. I’m not here to say please! I’m here to tell you what to do!" end task :clean_car do puts "I need you two fellas to take those cleaning products and clean the inside of the car. I’m talking fast, fast, fast!" end task :clean_crew do puts "Jim, the soap! O.K. gentlemen, you both been to county before I’m sure. Here it comes!" end task :get_rid_of_evidence_at_monster_joes do puts "So what’s with the outfits? You guys are going to a Volleyball game or something?" end task :drive_into_the_sunrise do puts "Call me Winston!" end task :solve_bonnie_situation => [:get_mr_wolf, :calm_down_jimmy, :figure_out_bonnie_situation, :get_vince_vega_in_line, :clean_car, :clean_crew, :get_rid_of_evidence_at_monster_joes, :drive_into_the_sunrise] do puts "You know, I’d go for breakfast. Feel like having breakfast with me?" end
If you run the rake task that depends on the other, we’ll get the following output:
Shell
$ rake solve_bonnie_situation You ain’t got no problem Jules, I’m on it! Go in there and chill them out and wait for the wolf who should be coming directly! Jimmy, do me a favor, will you? I smelled some coffee back there. Would you make me a cup? If I was informed correctly, the clock is ticking. Is that right Jimmy? Come again? Get it straight buster. I’m not here to say please! I’m here to tell you what to do! I need you two fellas to take those cleaning products and clean the inside of the car. I’m talking fast, fast, fast! Jim, the soap! O.K. gentlemen, you both been to county before I’m sure. Here it comes! So what’s with the outfits? You guys are going to a Volleyball game or something? Call me Winston! You know, I’d go for breakfast. Feel like having breakfast with me?
The order in which you define your rake tasks has no effect on the output—only the order in which you place the prerequisite tasks in the array for task dependencies. Also, please use the hashrocket =>
syntax for this.
A long list of dependencies might be a code smell. If you have to deal with something long, clean it up by encapsulating it inside a method which we then pass as a prerequisite.
def mr_wolf_tasks [:get_mr_wolf, :calm_down_jimmy, :figure_out_bonnie_situation, :get_vince_vega_in_line, :clean_car, :clean_crew, :get_rid_of_evidence_at_monster_joes, :drive_into_the_sunrise] end ... task :solve_bonnie_situation => mr_wolf_tasks do puts 'You know, I’d go for breakfast. Feel like having breakfast with me?' end
In the context of prerequisites, one thing to keep in mind is that you only need to mention a namespace if you are outside the relevant one.
Some Rakefile
namespace :marsellus_wallace do task :call_winston_wolf do ... end end task :solve_bonnie_situation => 'marsellus_wallace:call_winston_wolf' do ... end namespace :marsellus_wallace do task :call_winston_wolf do ... end task :solve_bonnie_situation => :call_winston_wolf do ... end end
Important to note, though: in case you do need to mention the namespace, you have to pass the prerequisite as a string => 'marsellus_wallace:call_winston_wolf'
.
Of course, the examples above are goofy and not real-life examples, but the intention was to show you how prerequisites work and how you’d put them together while they depend on each other.
Passing Arguments
You have two options to pass arguments to Rake tasks: either by using Bash variables or by making use of Rake’s syntax itself.
ENV Variable
In case you haven’t played with Bash before—or Bash sounds like gobbledegook to you—let’s take five and start from the beginning. Bash in your shell offers two sorts of variables: global (aka environment) variables and local ones. Both are written in uppercase. The environment variables are global ones, which means they are available in all shells and don't vanish when you close one—unlike local Bash variables, which are only available in the current shell.
Environment variables can contain data that can be used by multiple applications and are often used as a handy way to share configuration settings. In contrast to that, local Bash variables are just that, local. In our context of using Rake, you have the ability to access both via Ruby and in effect pass variables from the command line.
FYI
Just as a little aside, if you type env
or ENV
in your shell, you’ll get access to a whole bunch of environment variables. I redacted the list, but for a better understanding of what environment variables are and what they include, I encourage you to run it for yourselves.
Shell
env
Output
TERM_PROGRAM=Apple_Terminal TERM=screen-256color SHELL=/bin/bash TMUX=/private/var/folders/4z/3np9k5ks62b1xpbn_w_lmrgh0000gr/T/tmux-504/default,4146,0 EDITOR=vim LANG=en_US.UTF-8 TMUX_PANE=%1 is_vim=echo "#{pane_current_command}" | grep -iqE "(^|\/)g?(view|n?vim?x?)(diff)?$" ... ... ...
If you want to see a list of local Bash variables, you can run set
.
Shell
( set -o posix ; set ) | less
The set
command gives you a lot more output, but the above shows you the relevant bits right away.
Ruby’s ENV Class Method
Ruby offers a way to use environment and local Bash variables alike via a hash-like accessor. For our needs, when we pass a variable to a Rake task, it’s going to be a local Bash variable, which you can find in the list of variables running set
or a variation of it. Ruby can read it out using ENV['VARIABLE']
.
Shell
rake prepare_book BOOKTITLE='Confessions of a unicorn'
What I want to make clear, though, is that this variable won’t get added to the ENV list that your system uses—the stuff that you saw calling env
from the shell. To add it to that list, you would need to export
it. This is another story, but I thought I should make this clear.
Some Rakefile
task :prepare_book do book_title = ENV['BOOKTITLE'] || 'Working Title' puts "Do something with the #{book_title}" end
In this task definition, you can see how we prepared to accept or incorporate the variable passed to the task invocation. Ruby’s ENV[BASHVARIABLE]
does all the heavy lifting. If BOOKTITLE
had been a global environment variable, though, we could have accessed it inside this task definition as well with this syntax.
Rake Parameter Syntax
The second approach is using pure Rake syntax. You simply pass variables into square braces. That approach is better, and you can keep things more isolated. Why involve Bash if Rake is perfectly capable of handling this? Plus you don’t have any Bash variables floating around that way. If you want to pass multiple arguments into a task, it’s a lot more elegant as well.
Shell
rake "create_mi6_agent[James, Bond, 007]"
Some Rakefile
task :create_mi6_agent, [:first_name, :last_name, :number] do |t, args| puts "Number #{args.number} is commander #{args.first_name} #{args.last_name}." end
When you pass in more arguments than you have defined in your task, you can simply access them via args
. args.extras
displays an array of all the additionally passed in parameters. args.to_a
shows you all the parameters—in an array as well, of course.
Tasks of Interest
Below is a short list of Rake tasks that come with Rails:
- db
- doc
- tmp
- stats
- notes
- about
- secret
- assets
- routes
db
Below are a couple of useful tasks under the db
namespace for running Active Record migrations:
rake db:version
prints the current version of the schema. The output looks something like this:
Current version: 20160129135912
rake db:migrate
runs the last migration(s)—those which haven’t run yet. You can also pass it a specific migration to run.
Shell
rake db:migrate VERSION=20080906120000
rake db:create
creates your database. If defaults to the development and test databases.
db/development.sqlite3 db/test.sqlite3
rake db:test:prepare
makes sure that migrations that are already run on your development database are also run for your test database. If the test database’s schema were out of sync with your development database, it would not be very useful, of course.
rake db:drop:all
drops both test and development databases by default.
rake db:migrate:up
, rake db:migrate:down
runs the up
and down
methods for the migration in question.
rake db:redo
ensures that, after you have run a migration, the migration is reversible. It runs rake db:down
first and then rake db:up
.
rake db:rollback
undoes the last migration.
rake db:drop
drops by the development and test databases by default.
rake db:reset
drops the databases first and sets them up again by loading the schema and seeding the database.
doc
rake doc:app
generates documentation under doc/app
. It creates HTML pages about your source code for easy browsing. Pretty cool!
Screenshot
rake doc:rails
generates an API documentation under doc/api
—also as HTML pages. Handy if you are offline, I guess.
tmp
The tmp
directory in the root directory of your Rails app is the place for temporary files—most prominently files for sessions and cache. rake tmp:create
sets you up with everything you need for dealing with temporary files. rake tmp:cache:clear
clears the tmp/cache
directory. rake tmp:sessions:clear
clears the tmp/sessions
directory.
stats
rake stats
gives you a nice overview of your app.
+----------------------+-------+-------+---------+---------+-----+-------+ | Name | Lines | LOC | Classes | Methods | M/C | LOC/M | +----------------------+-------+-------+---------+---------+-----+-------+ | Controllers | 89 | 69 | 6 | 18 | 3 | 1 | | Helpers | 13 | 13 | 0 | 1 | 0 | 11 | | Models | 89 | 54 | 6 | 7 | 1 | 5 | | Mailers | 0 | 0 | 0 | 0 | 0 | 0 | | Javascripts | 25 | 0 | 0 | 0 | 0 | 0 | | Libraries | 0 | 0 | 0 | 0 | 0 | 0 | | Controller specs | 99 | 81 | 0 | 0 | 0 | 0 | | Feature specs | 14 | 11 | 0 | 0 | 0 | 0 | | Helper specs | 45 | 12 | 0 | 0 | 0 | 0 | | Model specs | 10 | 8 | 0 | 0 | 0 | 0 | | View specs | 60 | 48 | 0 | 0 | 0 | 0 | +----------------------+-------+-------+---------+---------+-----+-------+ | Total | 444 | 296 | 12 | 26 | 2 | 9 | +----------------------+-------+-------+---------+---------+-----+-------+ Code LOC: 136 Test LOC: 160 Code to Test Ratio: 1:1.2
notes
You can leave notes in your code. You can prefix them in your comments with TODO
, FIXME
, OPTIMIZE
.
Some Ruby file
# FIXME Something to fix here class Agent < ActiveRecord::Base belongs_to :operation belongs_to :mission ...
When you run rake notes
, Rake parses these prefixes and gets you a list of all these notes from your code.
Shell
app/models/agent.rb: * [1] [FIXME] Something to fix here
You even get a detailed list where you find them—directory, filename, line number [Line Number]
, everything is included. Awesome, right?
about
rake about
gives you an overview of version numbers for:
- Rails
- Ruby
- RubyGems
- Database adapter
- Schema version
- Middleware
- Application root
and lots of other useful information.
secret
If you are paranoid about your session key and want to replace it, rake secret
will generate a new pseudo-random key for you. It doesn't replace the key for you, though. The output in the shell looks like this:
b40a74b94cd93fed370fd4f8f9333633c03990b7d9128383511de5240acf3fa6b6b07127e875814fdadb32f1aa44d69c4e82592b0ce97f763ea216a21e61881d
assets
rake assets:precompile
lets you precompile your assets under public/assets
. If you want to get rid of older assets, just run rake assets:clean
. Finally, running rake assets:clobber
deletes the whole public/assets
directory.
routes
rake routes
might be the most important one. It shows you all the routes in your app.
Final Thoughts
Writing Rake tasks without knowing what’s going on under the hood gets boring pretty quickly. This article was a little warm-up and introduction for people who wanted to peek into Rake for the first time.
I hope it covered all the basics without being too dry—after all, Rake is super dope and all, but at the same time, it’s maybe not the sexiest of toys. This basic knowledge of Rake, though, should give you all you need to get dangerous and expand your knowledge of the Rake tasks that are at your disposal.
Comments