[Railways] Railways does not work when the RubyMine project root is other than the Rails root directory.

Conclusion

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

Cause

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]

background

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.

Additional Information

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?

Summary

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

[Railways] Railways does not work when the RubyMine project root is other than the Rails root directory.
When the project is not displayed in eclipse
When the server does not start with rails s
[Ruby on Rails] When parameter id acquisition does not work
[Rails] Solving the problem that session timeout does not work
Docker does not work when DOCKER_HOST is specified in WSL2
[Rails] When the layout change of devise is not reflected
When the form such as Select of Materialize does not work properly
[Rails] Annotate is not executed when migrating
What to do when rails db: seed does not reflect in the database
Does the escape sequence (\) not work? (for Mac)
When @Transactional of Spring Boot does not work
Does not recognize the library when implementing jcaptcha
[Ruby on rails] When executing the heroku command, bash: heroku: command not found is displayed. [Rails tutorial]
Processing when an ID that does not exist in the database is entered in the URL
"Do not show again" check does not work in the warning dialog when starting applet
[Note] When the page access speed does not increase
PATH does not pass ... The cause is the character code
Fixed the phenomenon that vuetify built in Rails is not loaded when page transition is done
How to solve the problem when the value is not sent when the form is disabled in rails and sent
A memo when the incoming number acquisition using Broadcast Receiver does not work on Android 9/10
[Rails] Record when the event did not fire when the javascript file name is the same as the controller
What to do when Rails on Docker does not reflect controller changes in the browser