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.
1 2rails g migration create_users 3
Above command creates a migration. Now we need to run that migration.
1 2rake db:migrate 3
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.
1 2rails console development 3
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.
1 2$ rails rails:update 3 4$ rails rails:template 5 6$ rails rails:templates:copy 7 8$ rails rails:update:configs 9 10$ rails rails:update:bin 11
So, Rails team decided to change the namespace
for these tasks from
1 2$ rails app:update 3 4$ rails app:template 5 6$ rails app:templates:copy 7 8$ rails app:update:configs 9 10$ rails app:update:bin 11
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.
1 2$ rake routes | grep pattern 3
There is an effort underway to have a Rails command which might work as shown below.
1 2$ rails routes -g pattern 3
There is also an effort to enable lookup for controller like this.
1 2$ rails routes -c some_controller 3