Download the Windows version of Ruby + Devkit and install it. Note that if you change the default installation path, you will need to change the settings separately for some gems that will be installed after this.
Operate from the Visual Studio Code terminal. The terminal is opened at the bottom of the screen by selecting "New Terminal" from "Terminal" in the menu.
gem install rubocop
gem install ruby-debug-ide
gem install debase
gem install rcodetools
gem install ruby-lint
gem install reek
gem install faster
gem install debride
Install "Ruby" from the Visual Studio Code extension.
Go to "File"-"User Settings"-"Settings" in the menu and search for "ruby". Click "Edit with setting.json" and edit setting.json as follows.
setting.json
{
"ruby.codeCompletion": "rcodetools",
"ruby.format": "rubocop",
"ruby.lint": {
"reek": true,
"rubocop": true,
"ruby": true,
"fasterer": true,
"debride": true,
"ruby-lint": true
},
"ruby.intellisense": "rubyLocate",
"ruby.locate": {
"exclude": "{**/@(test|spec|tmp|.*),**/@(test|spec|tmp|.*)/**,**/*_spec.rb}",
"include": "**/*.rb"
}
}
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Lical File",
"type": "Ruby",
"request": "launch",
"program": "${workspaceRoot}/hoge.rb"
}
]
}
At this point, you can debug the .rb file while stopping it at a breakpoint. To stop at a breakpoint, click to the left of the line number to add a red point. Then, select "Run" from the menu and then "Start Debugging". Next, set up Ruby on Rails to work.
Enter the following in the Visual Studio Code terminal. In the following example, PostgreSQL is specified for DB. Create a project named "test_project" and debug it with the last "rails s".
gem install bundler
install rails
rails new test_project -d postgresql
cd test_project
bundle install
rails s
If something is missing, an error will occur, so follow the steps below.
If you read the error message and are told that webpacker is not enough, install it below.
rails webpacker install
If you're told you're missing Node.js or Yarn, download and install it.
Download Node.js Download Yarn
With the above, the local server is started by "rails s". When you open "localhost: 3000" in your browser, the Rails page is displayed.
If Rails does not start because port number 3000 is duplicated with other services, you can add the port number specification to launch.json.
Recommended Posts