RubyMine Get version 4 FREE

RubyMine Quick Start Guide

Welcome to RubyMine! This Quick Start Guide aims to introduce you to RubyMine's main concepts and most basic features of the IDE. Buckle up!

Before You Start…

  1. Make sure a Ruby interpreter is downloaded and installed on your computer. RubyMine supports Ruby versions 1.8.6 to 1.9.x. Please follow these download and installation instructions. Note that depending on your platform, you can use MRI Ruby, JRuby, MacRuby, Rubinius, or IronRuby. Note: We recommend RubyInstaller for Windows and RVM for Mac OS X and Linux.
  2. You will also need RubyGems to extend functionality of your applications. Both RubyInstaller and RVM have RubyGems bundled.
  3. If you are going to use RubyMine for Ruby on Rails development, note that RubyMine can automatically download and install any needed version of Rails framework for you on project creation.

Important Note

RubyMine comes with several pre-defined keymaps; so if you are used to working with TextMate, Visual Studio, or Eclipse, you can just select your favorite keymap (File | Settings - IDE Settings - Keymap).

In this quick start guide, we use the default one. If you want to use a different keymap, keep in mind that certain commands have different mappings, or no mappings at all. If this is the case, refer to the section Configuring Keyboard Shortcuts to learn how to create the missing mappings.

Create/Open Your Rails Application

Create/Open Your Rails Application

Let's start from the very beginning, that is creating a Rails application from scratch. It's most easy: choose File | New Project on the main menu, enter project name and select its type — for example, Rails application.

Now let's do some fine tuning: choose Ruby interpreter, Rails version, Rails template (if any), and the database to be used for your application. As mentioned above, you might have not installed Rails in advance, and RubyMine reports about that in the Rails version field. No problem – just click the browse button next to the field, and select which Rails version do you want installed, together with the dependent gems and documentation.

Download and install Rails gem

When the settings are done, RubyMine will run Rails app generator and let you observe results in the console.

If you want to continue developing an existing Rails application and see how nice is working on it in RubyMine, choose File | Open Directory... on the main menu. Find the folder that contains your project source code, select it and open.

See also:
Watch "Open project in RubyMine" demo (0:30)

Customize Everything!

Customize Project Settings

Look at the main toolbar — there is the Settings button settings. Clicking this button opens the Settings dialog box, where you can change your project structure, configure Ruby gems, set up version control, and tweak your working environment to make the development process a real pleasure.

Gems

Naturally, your projects makes use of Ruby gems. RubyMine's support of gems is twofold.

First, this is the Gem Manager – it helps you install the gems you need, and update those already installed.

So... click settings, and select Ruby SDK and Gems page. Install and Update buttons will bring forward the powerful Gem Manager UI that will help you keep abreast with the ever-changing gems repositories, update to the latest versions, and download the required gems.

Gems

The further approach of RubyMine to the gems depends on the presence of the Bundler.

  • If your project uses the Bundler, then all the required gems are taken according to the Gemfile.
  • If there is no Bundler, RubyMine scans all the project files for the calls to Ruby gems, and produces a set of the required gems. If for some reason you are not happy with the set of gems defined by RubyMine, you can create a Gemfile yourself and specify the gems of your choice.
See also:
RubyMine Blog posts about Gem manager

VCS

Surely, you keep your sources under a version control, right? Git? SVN? With RubyMine, it's easy to set up, and again the IDE does a good job auto-detecting the VCS already used for existing projects. But you can fine-tune (remember settings) — just click Version Control node in the Settings dialog. By default, you will see project root directory only, but you can break your application down into smaller chunks, and place virtually every directory under its own version control system.

Check out from Version Control

In the Settings dialog, you can also define some behaviors that are common to all version control systems: confirmation on creating or deleting files, tasks performed in the background, ignoring unversioned files and more.

Besides that, you can check out files from a VCS repository, without actually having enabled any VCS support (Version Control | Check out from Version Control), and even without an opened project (Welcome Screen | Check out from Version Control). This might be helpful, if you want to create a project around some code taken from VCS.

IDE and Editor

Editor Misc Stuff

Working in an IDE actually means living in it, and it is quite natural to make your haunted place pleasant for your eyes and comfortable for your fingers. That's why RubyMine makes it possible to choose the look and feel of the IDE and the editor, configure your preferred set of keyboard shortcuts (keymap), fine-tune scrolling behavior, highlighting, and more.

All these settings are (again) configured in the Settings dialog: click settings, and see the list of pages under the IDE Settings heading. Here are three pages that might be of interest for the starter:

Appearance.
This is the page where you can select "look and feel" of your RubyMine installation. Just click the Look and feel drop-down, and select the scheme you like better. You don't need to close the Settings dialog to observe the results of your experiments: click Apply, see what happens, and close the dialog when you are quite happy with what you've got.

Editor.
The whole bunch of pages helps you tune every aspect of the editor's behavior. Note that RubyMine comes with several pre-defined color schemes – the default one on the white background, and some fashionable dark color schemes like vibrantInk, or Railscast. If you want to make up something very personalized, you are welcome to do it: select a scheme most similar to your "dream scheme", save it with a new name, and start changing its background, font, colors of syntactical elements, error highlighting etc., and immediately observe results in the preview pane.

Keymap.
The set of keyboard shortcuts you work with, is one of your most intimate habits – your fingers "remember" certain combinations of keys, and changing this habit is rather painful. With this in mind, RubyMine supplies you with a wide range of pre-defined keymaps, for those who prefer Eclipse, or for the TextMate fans, or for those who've had long experience with VisualStudio... Again, you can create you very own keymap on the base of an existing one.

And finally, there is a magic shortcut Ctrl+Back Quote that helps you switch between schemes (all of them – keymaps, colors, code styles, and L&F) without the Settings dialog (for Windows and Linux users only).

See also:


Rails View

Rails View

One of the major means of dealing with a project is the Project tool window. It shows a project as a tree of directories and files. However, if you are working with a Rails application, you might find it more convenient to detach from this traditional file-based view, and look at your project from a different point. This is what the Rails view is intended for. It shows the logical project structure, with its Controllers, Models, Views, or Migrations, rather that just files and directories, and helps gain quick access to the Rails application elements.

Switching to the Rails view is quite simple. All you have to do is to click View as drop-down list on top of the Project tool window, and choose Rails

See also:
Watch "Open project in RubyMine" demo (0:30)

Populate Your Application

Adding new files, directories, or Rails elements to your project is (as usual) just a snap: File | New... on the main menu, New on the context menu of the Rails view, or Alt+Insert⌃N for those who prefer using keyboard only (keymap), will show the menu of available elements.

This menu includes: file or directory, Ruby class, HTML or RHTML files, and other templates you may have added. For Rails applications, the list includes the Run Rails generator item that will help you create a model, a controller, a scaffold, and much more. By the way, it is usual for our keyboard-centric IDE that you can invoke this command immediately with a keyboard shortcut Ctrl+Alt+G⌘⌥G.

So, select the element of your choice, and enter its name. RubyMine will do all the rest: create files by templates with some initial source code, or run the selected generator in the console, and produce the complete structure of files and directories.

When a new file is created, RubyMine will suggest you to automatically put it under version control. 

See also:
Populating Projects Creating Rails Application Elements

Edit Code Smartly

Edit Smart

What makes RubyMine stand out from the numerous IDEs, is its full-featured editor. Whatever you do for developing your source code, RubyMine is always at hand, helping you create error-free applications. Here is a brief outline of the smart RubyMine's coding assistance:

  • At every stage of development, use code completion (Ctrl+Space⌘Space), which takes into account the current context. For example, depending on the place where you invoke code completion, you can complete keywords or code blocks, infer types, create chained queries etc.
  • Use live templates/snippets (Ctrl+J⌘J) or surround templates (Ctrl+Alt+J⌘⌥J) to produce entire code constructs. RubyMine comes with a wide range of ready-to-use live templates, or snippets, which you can explore in the Settings dialog.  If you see that you are lacking something especially important for your development goals, extend this set of snippets with your own ones.
  • Almost like a pair programmer, RubyMine keeps an eye on what you are currently doing, and comes up with smart suggestions, or intention actions, which are marked with a light bulb sign. If you want to know exactly what is there under the light bulb, click it, or press Alt+Enter⌥↩. This way you can, for example, auto-create a new method that you are already using in the code, but have not yet declared, or perform i18n for a string value.
See also:


Inspect Code with Deduction

RubyMine gives you numerous hints and prompts to help you avoid errors, or correct them, if they occur. First, as you type, you immediately have all syntactical errors underlined with a wavy line. If you place the caret at an error location, you will see a brief description of the problem at the tooltip, and also in the left side of the Status bar.

Unused Variable

The next level is static code analysis, or code inspections: your code is analyzed without actually executing it.

Actually, RubyMine inspects code in the current file on-the-fly, and shows inspection results in the marker bar as colored stripes. If you see that the right side of your IDE frame is bright with red stripes, beware — it means that your code contains serious errors. Less important things, recommendations to improve code, or warnings, are displayed as yellow stripes. Information for the current file is summarized in a colored indicator on top of the marker bar, which works as traffic lights: green means that everything is fine; at least one problem turns the indicator yellow or red.

However, you might want to look deeper into the code of your application. In this case, you have to inspect a whole project, or any of its parts (Code | Inspect Code), and explore results in the Inspection tool window. RubyMine comes with a wide range of pre-defined inspections; you can familiarize yourself, and configure them in the Inspections page of the Settings dialog settings.

See also:
Inspecting source code Unused local variable or parameter inspection

Get Rid of Duplicates

As time goes on, your project can eventually become rather cluttered up with repetitive pieces of source code. Sometimes these are exact copies, in certain cases the code constructs differ in names, but still are semantic duplicates. You can make your code more clean and compact by reducing such duplicated fragments.

To help you make you source code less entangled and more intelligible, RubyMine suggests search for duplicates functionality (Code | Locate Duplicates). It is up to you to define the area, where duplicates will be sought for (the whole project, a folder, ot just few files), and to which extent identity will be perceived.

RubyMine will show you the whole bunch of detected repetitive fragments in the Duplicates tool window. Now it is your turn to look thoroughly at the results and decide what to do with them. For example, you can further refactor you code, and replace duplicates with methods and method calls.

See also:
Search for duplicates in Ruby Analyzing duplicates

Find Your Way Through

Navigation facilities of RubyMine fall into major areas:

Source Code

Usages Search

Let's start with finding fragments of text. One of the most basic means of navigation and search in the source code is our good old Ctrl+F⌘F command: start typing your search string, and get immediately to its occurrences in the current file. But RubyMine goes further, and helps you look for a certain string within a directory, or any arbitrary scope, or an entire project (Ctrl+Shift+F⌘⇧F).

Besides that, RubyMine suggests a more sophisticated approach, namely search for usages. For example, if you want to navigate from a symbol to one of its usages within your application, press Alt+F7⌥F7, or choose Find Usages on its context menu. Actually, there are several commands that help you find out where a certain symbol is used: you can jump from one usage to another in the current file (Ctrl+F7⌘F7), view usages in the current file color-coded (Ctrl+Shirt+F7⌘⇧F7), or across a whole project in a popup list (Ctrl+Alt+F7⌘⌥F7).

To quickly navigate from a symbol to its declaration just middle-click its name, or hit Ctrl+B⌘B.

Model Dependency Diagram

And finally, do not miss the Model Dependency Diagram (under View menu) to take the bird's view on your models and relations, and use it as a handy means of navigation.

Now let's look deeper into Rails-specific navigation.

  • What shall you do to jump from a controller action to its associated view? or from a test to its subject? go up and down through the method hierarchy? For all these purposes, RubyMine suggests special icons in the left gutter of the editor: for example, View to navigate to a view, or settings to navigate to a controller or action.
  • If you are in certain element of a Rails model, and want to find its related components, use the Go to | Rails command (Alt+Shift+N⌥⇧N), and select the one you want to explore from the list in the Rails popup window.

Project Elements

Go to Symbol navigation

To quickly find an element by name and open it in the editor, use navigation popup: press Ctrl+N⌘N (for a class), Ctrl+Shift+N⌘⇧N (for a file), or Ctrl+Shift+Alt+N⌥⌘⇧N (for a symbol), and start typing the name you are looking for. The list of matching names shrinks as you type, but this is just one of the handy facilities: you can use the asterisk wildcard, all caps for CamelHumps, or spaces for snake_case names, slashes for nested folders and so on, and so forth.

Quick search is the most easy way to find a file: with the Project tool window having the focus, you just start typing, and see how the matching nodes are highlighted in the tree view. Actually, this method of finding files or symbols works in any tool window.

IDE Components

Tab Switcher popup

Ways to navigate across the IDE are numerous, and we'll briefly outline just some of them. Let's start with the switcher: press Ctrl+Tab⌃Tab to show the switcher, which is a list of the RubyMine's tool windows and open files, and then, keeping the Ctrl key pressed, use Tab or arrow keys to scroll to the component you want to go to.

If you select a file in one of the IDE components, and want to view it in another one (the editor, Project view, Rails view, Navigation bar, or a changelist), then use Select Target (Alt+F1⌥F1).

And finally, don't forget that pressing Esc will bring you back to the editor, wherever you are!

See also:


Run and Debug Your Rails Application

Debugger: evaluate expression

While working with RubyMine, you'll come to a moment when you need to run or debug a Ruby or Rails script, a Rake task, a test, or a Cucumber scenario. In all these cases, you need a special profile, or a run/debug configuration, which defines script name, working directory, environment variables, and other vital execution configurations.

For each of the elements that can be run, there is a default profile, and you can easily launch such an element from its context menu, or with a handy shortcut Ctrl+Shift+F10⌃⇧F10. However, if you want to use some other run/debug configuration, you have to choose one on the main menu, and then press Shift+F10⇧F10.

Oops... your application or script runs into a run-time error? To find out its origin, you will have to do some debugging. It starts with placing breakpoints, at which program execution will be suspended, so you can explore program data. Launching the debugging session is quite as simple: either use the context menu of a specific script, or select a suitable run/debug configuration, and then press Shift+F9⇧F9.

And finally, a very convenient way to select run/debug configuration and immediately launch it is Alt+Shift+F10⌥⇧F10/Alt+Shift+F9⌥⇧F9.

Besides that, RubyMine suggests some additional commands:

  • Tools | Run Rake Task command helps find a Rake task by its name, and run it.
  • Use keyboard shortcut for Rake tasks (remember running Rails generators?) Ctrl+Alt+R⌥R.
  • Those who prefer consoles, have a chance to launch IRB (Tools | Run IRB Console), or Rails (Tools | Run Rails Console) console, and work there, same way in the regular consoles, without leaving the IDE.
See also:
Blog posts about running/debugging in RubyMine

Create and Run Tests

Debugger: evaluate expression

We won't discuss here why writing tests is important :-) Let's just assume it, and explore RubyMine's testing support, which extends to all major testing frameworks for Rails: Test::Unit, Shoulda, Test-Spec, RSpec, and Cucumber. Whichever one you will use for testing, you will enjoy framework-aware coding assistance, run/debug configurations, special generators to automatically create a complete set of testing scripts and directories, and framework-specific code inspections. Most important is the possibility to run tests and explore results without leaving RubyMine, in a nice and handy test runner.

Let's outline in brief the necessary steps required for testing:

  • First, when you decide which testing framework you will be using, install and attach the required gems (remember settingsRuby SDK and Gems ?). Thus you will be able to get context menu commands and code completion.
  • Create run/debug configuration for your testing framework (Create <name> on the context menu of a test, or Create All in: <container> on the context menu of a container), unless you are quite happy with the default one.
  • We have already looked into the process of populating applications — so, creating tests falls into the same category. Alt+Insert⌃N suggests a list of test templates, so you can select the one you need, and add some meaningful code to describe your testing goals.
  • Launch a test. Note that RubyMine allows launching all tests in a directory, test scripts or scenarios, and even individual test methods or examples. So, to run a test, just choose Run <name> or Run All in: <name> on the context menu.
  • And finally, view and work with the test results in the test runner UI that opens in the special tab of the Run tool window.
See also:


That's it folks!

Here we have given a very concise overview of some vital RubyMine facilities, just to give you a quick start. There are numerous important features that make developer's life nice and easy, and the source code nice and clean. Try now these primary steps, and then dig deeper. Enjoy!

We realize you may still have questions. We welcome you to ask them on RubyMine Discussion Forum.