This blog is part of our Rails 5 series.
In Rails 4 some commands start with
rails and some commands start with
rake. This could be quite confusing for people new to Rails. Let’s see
Our task is to write a database migration and then to run that migration.
Above command creates a migration. Now we need to run that migration.
As you can see first command starts with
rails and second command
In order to consolidate them we can either use
rails for everything or
we can use
rake for everything.
Choosing rails command over rake command
Some favor using
But an important feature missing in Rake
is the ability to pass arguments.
In order to execute the above command using
we will have to pass
as arguments. We can pass these values using environment variables.
That would mean adding additional code in Rake task to fetch right
values and then only we will be able to invoke command
rails console development.
Rails 5 enables executing rake commands with rails
Rails core team
to have consistency by enabling
rails command to support
For example in Rails 5 commands like
test etc which are part of
rake command in Rails 4 are
now being supported by
However you can still choose to use
rake to run those commands similar to how
they were run in Rails 4.
This is because Rails community has
introduced Rake Proxy
instead of completely moving the command options from
What happens internally is that when
rails db:migrate command is executed, Rails checks if
db:migrate is something that
rails natively supports or not.
In this case
db:migrate is not natively supported by
so Rails delegates the execution to Rake via Rake Proxy.
If you want to see all the commands that is supported by
Rails 5 then you can get a long list of options by executing
Use app namespace for framework tasks in Rails 5
rails command is now preferred
few rails namespaced framework tasks
started looking little odd.
So, Rails team decided to change the namespace
for these tasks from
rails rails:update will now give deprecation warning like:
DEPRECATION WARNING: Running update with the rails: namespace is deprecated in favor of app: namespace. Run bin/rails app:update instead.
More improvements in pipeline
In Rails 4, the routes are usually searched like this.
There is an effort underway to have a Rails command which might work as shown below.
There is also an effort to enable lookup for controller like this.