Create a Rakefile
in the project root directory.
# Rakefile
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
#Below is the application from the project root directory to the Rails root directory.Specify the relative path to rb
require_relative 'path_to_your_rails_app_root/config/application'
Rails.application.load_tasks
The Railsways plugin runs rake routes
internally, which seems to use the RubyMine API. [^ 1]
(Probably using RubyMine's Run Anything
)
Command execution with Run Anything
is done in the project root directory.
Therefore, if you want to run the rake command with Run Anything
, you need to create a Rakefile
in the project root directory.
There was also a description of this in the official help. [^ 2]
Personally, Railways was very useful and I used it a lot. However, when adding a front end or Terraform to an application, I wanted to manage the directories separately. Then, until now, the project root directory = Rials root, but the configuration is as follows.
.
├── terratorm
├── frontend
├── backend # Rails App
├── docker-compose.yml
└── README.md
Rakefile
is gone.
In this state, Railways did not work and I was in trouble.
If you open the backend
directory with RubyMine, it will work, but if you do that, it will be difficult to access other directories and it will be less convenient.
I didn't want to let go of Railways when developing it, and I was wondering if it could be done.
By the way, Railsways execution tasks can be changed in the settings.
(Rialsways > Settings > Rake task name)
By default, it is routes
, and you can see that the command is executed by giving rake
as a prefix.
Therefore, at first I thought that it could be dealt with by changing this execution command, but it was impossible.
I changed the content to -f path_to_your_rails_root / Rakefile rouets
so that rake -f path_to_your_rails_root / Rakefile rouets
is executed, but I get the following error.
rake aborted!
No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb, Rakefile.rb)
/Users/xxxxxx/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/application.rb:698:in `raw_load_rakefile'
/Users/xxxxxx/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/application.rb:104:in `block in load_rakefile'
/Users/xxxxxx/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/application.rb:186:in `standard_exception_handling'
/Users/xxxxxx/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/application.rb:103:in `load_rakefile'
/Users/xxxxxx/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/application.rb:82:in `block in run'
/Users/xxxxxx/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/application.rb:186:in `standard_exception_handling'
/Users/xxxxxx/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/application.rb:80:in `run'
/Users/xxxxxx/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rake-13.0.1/exe/rake:27:in `<top (required)>'
I specified the Rake file with the -f
option, but why ...
It was useless to specify it with an absolute path.
In addition, Run Anything
could be run without the Rakefile
in the project root with the -f
flag.
I thought I was using Run Anything
internally, but maybe it's different.
Where on earth are Railsways tasks performed?
Until now, I wasn't particularly conscious of Rakefile
, and when I investigated this time, I knew its role.
It was this harvest that made me more familiar with rake
during my research.
I hope this article helps someone.
Recommended Posts