Here I will show how I set up RubyMine. I will setup a project from an existing codebase and list the extras that I can get rid of.
Theses are my personal preferences and suit my workflow both personally and proffessionally.
Opening an existing repo
Ok so I already have RubyMine installed and linked to my GitHub account 🤦♂️
I will open RubyMine and select “Get from VCS”.
I’d then seelct “GitHub” from the sidebar, and (optionally) type the repository name into the search bar.
Select the repository from the list and select or type 🤮 a directory into the “Directory” input. Note that the directory should include the name of the repository that you’re cloning - in my case /Users/dcyoung_dev/Projects/project_name
Click “Clone” and sit back
Project Dependancies
Most if not all of my repositories are Ruby on Rails projects and I have made an effort to convert them all to use asdf-vm for managing Ruby and Node versions.
In my projects I also have a [bin/setup
file] to make life easy. Before running that I manually set the Ruby SDK version in RubyMine as, for some reason, it does not pick this up from the .tool-versions
file 🤷♂️
Setting Ruby SDK
Check which version of Ruby that your project needs, for me I would look in .tool-versions
, .ruby-version
and lastly in the Gemfile
. For this example I’m using ruby 3.0.1
.
Open “Preferences”1 and type “sdk”. RubyMine automatically searches and highlights when you start typing in most menus 👍. You should see that the “Languages & Frameworks -> Ruby SDK and Gems” menu item has been selected and your available SDKs should be visible in the main panel.
Select the correct SDK if it is visible and click “ok”. skip to the next section
In my current set up ruby 3.0.1
is not available so I will have to move to the terminal briefly.
Open the terminal, navigate to your project folder and manually run asdf install
after Ruby has insalled select the correct SDK in RubyMine 👍 - I also had to restart RubyMine 🤦♂️
Setting up Rails
From the “Project” window, navigate to /bin/setup
and right click on the setup
file.
Select “Modify Run Configuration…” from the dropdown.
RubyMine is very clever when running scripts/files, especially when those files are written in Ruby. The setup
script has a couple of steps that will set up your Rails environment and for that it requires not to be run using bundler
.
From the configuration menu, select the “Bundler” tab and select “Disabled” from the “Run script in the context of the bundle (‘bundle exec’)” menu.
For this script we have told RubyMine not to run bundle exec bin/setup
allowing it to run bin/setup
.
This setting only applies to the bin/setup
. Most of the time you’ll want to let RubyMine do it’s magic.
Installing all the things
You’ll now have a few ways of running the bin/setup
script. Right clicking the file and selecting “Run ‘setup’”, opening the file and clicking the “Play” button next to the start of line 1, or you’ll see “setup” in the “Run/Debug” toolbar at the top of RubyMine.
My preference is to use the “Run/Debug” toolbar as that’s where our “dev” command will live too.
Running Rails server
For most projects I add a Procfile.dev
[^rails-7-procfiile] and a [bin/dev
file].
Before running the bin/dev
file for the first time we have to modify the run configuration. This file is a bash script and needs a few options changed.
From the “Project” window, navigate to /bin/dev
and right click on the dev
file.
Select “Modify Run Configuration…” from the dropdown.
From the configuration menu, in the “Working directory” input, remove the bin
from the end. This will ensure that bin/dev
executes from the main project folder rather than the bin
folder.
Also uncheck the “Execute in terminal” checkbox. This will cause RubyMine to run it in the same “Run” window, similar to the bin/setup
script.
Click “Ok” to save these settings. You should now see “dev” in the “Run/Debug” toolbar. Next to “dev” click the “play” button. You should see your server(s) start up in the “Run” window.
[^rails-7-procfile] since Rails 7, this is generated if you use a CSS or JS bundler like esbuild
Slimming down buttons and toolbars
RubyMine can be overwhelming with the amount of buttons, toolbars, windows and options. A lot of which can be removed if you like.
I’ve found that over time I’ll try out new windows or toolbar options to see what they do. Some of which turn out to be incredibly useful - I recently discovered the “Endpoints” window 😲
Removing toolbar buttons
Around the “Run/Debug” toolbar there are many buttons, I’ve removed some of these I don’t use.
Right click on the toolbar and select “Customize toolbar…”. I remove the following
- “Save to Platform”
- “Reload Remote References”
- “Show OpenAPI Preview”
- “Perform Security Audit”
- “CodeWithMeNavbarGroup” and everything inside it
- “Toolbar Run Actions” -> “Run/Debug” -> “Run with Coverage”
- “Toolbar Run Actions” -> “Run/Debug” -> “Profiler”
Removing sidebars
To remove items from your sidebars, right click on them and select “Remove from Sidebar”. If you need/want to add them back to a sidebar, select “View” from the top of your screen and then select “Tool Windows” and open whichever item you wish, these will automatically be added back to a sidebar.
On my default view I can see the following:
- Left sidebar
- Top
- “Project”
- “Pull Requests”
- Bottom
- empty
- Top
- Right sidebar
- Top
- “Database”
- Bottom
- empty
- Top
- Bottom sidebar
- Left
- “Git”
- “Run”
- “TODO”
- “Terminal”
- Right
- empty
- Left
It can be assumed that tools that are not listed here have been removed from sidebars.
Viewing the Rails database
Most Rails projects will have a database attached and RubyMine provides a few integrations that will help with viewing your data.
For my projects I use Postgres, which is supported by default in RubyMine.
Connecting to Postgres
Make sure your Postgres server is running. In a terminal run brew services list
and you should see postgresql@14 started
.
Click on the “Database” in your sidebar (mine is at the top of the right hand-side) to open the Database tool window.
Click on the “+” icon, hover over “Data Source” and select “PostgreSQL”.
If you have not made any user or password changes to your database, then you can click the “Test Connection” link near the bottom of the “Data Sources and Drivers” popup. You should see a “Successded” message. If not you may need to fill in some more details 🤷♂️
Click on the “Schemas” tab, where you should see a list of all the databases available. Your project’s database should be listed here. If not try running bin/setup
again or try rails db:prepare
in the terminal.
I normally uncheck the “Default database” and check the “your_project_name_development” database.
Expand the “your_project_name_development” database and you should see a list of “schemas” - if you do not, select the “your_project_name_development” database and then click the “Refresh” icon in the window. Check the “public” schema from the list and click “OK” to close the window.
You should now see your project’s database in the Database tool window. Expanding the database, “public” schema and the “tables” folder, you’ll see all the tables created for your project. Double clicking on a table name will open up a view of the data in that table 🧐
Tasks
The task functionality allows you to link up to your task list service like Trello and GitHub (Issues). From the
Branch naming
To set up automatic branch creation when you start a new task, we can customise how the branch names are created. For most of my projects I like to include my initials, a human readable description and a task id. dy/some_new_feature-1234
Open “Preferences”1 and type “tasks”.
Select “Tools -> Tasks “ from the menu.
From here we can use the RubyMine syntax to create branch names and changelist names. e.g. dy/${summary}_${id}
. I also select the “Lowercased” option and use _
in the “Replace spaces with” options.
Click “OK” to save the settings
Task Servers
Open “Preferences”1 and type “tasks”. Select “Tools -> Tasks -> Servers” from the menu. Click on the “+” icon, and select “GitHub” or whatever task management system you use. Complete the repository settings form and follow any authenitcation prompts. Use the “Test” button to test the connection.
Click “OK” to save the settings
Using tasks
To start a new task click on “Default task” from the “Tasks Toolbar” and select “Open Task…” from the drop down. You should now be able to select a task from your task server or create a new task.
From the popup you can override any of the naming and choose how to create your new branch.
Selecting “OK” will create and switch to your new branch, which you can see at the bottom right of RubyMine.
If you had any files open before you started your task , you may see that they have been closed. The benefit of Tasks is that when you switch back to your previous task, the files that you were looking at will reopen. This is really handy when switching contexts within a project.
Code linting
In my Ruby projects I use the standardrb
gem. Unfortnuately RubyMine does not auto-detect this, therefor eyou have to change the settings yourself. Here is a link to the help docs for changing the settings.
In your editor you may see squiggly lines under some code. You can right click on the underlined text and select “Show Context Actions”. Selecting “Fix all auto-correctables offences”, RubyMine will atempt to fix the code in the file, based on [standardrd
] rules.
WIP
Running test suite
Running test suite on code change
Viewing Database
Changing data
Writing SQL
File viewer
Quick Search
- Double shift
Rails controllers and view quick links
Command Click
- Jump to source of Class, Method, Variable