Book Image

Instant RubyMine Assimilation

By : David L. Jones
Book Image

Instant RubyMine Assimilation

By: David L. Jones

Overview of this book

Ruby and Ruby on Rails applications can become very complex very quickly, with hundreds of different files to contend with during a typical day of development. With RubyMine, you can become much more productive and let the IDE take care of the menial tasks while you concentrate on the details and structure of your applications. Instant RubyMine Assimilation shows you how to integrate the RubyMine development environment into your everyday development process. With step-by-step instructions and practical examples, you will learn how to customize the environment precisely to suit your needs, debug and test your code, and get the most out of many other features of RubyMine. Starting with the installation of RubyMine on your preferred platform, this guide will walk you through creating your first program. You will be taken through everything from the development and testing process all the way to deploying your website for the world to enjoy. You will learn how to manage your project in RubyMine including integrating version control, testing, and debugging your projects. Furthermore, you will learn how to navigate complex projects, view database tables, and utilize the built-in console and deployment tools of RubyMine, all of which will help you become an expert developer This book will also teach you how to install and use Gems, change Ruby environments, and use code coverage and reports to enhance your testing. By the end of this book, you will be able to confidently deploy your Rails application to a server, all within the inviting environment that is RubyMine.
Table of Contents (7 chapters)

First communication – saying hello (Must know)


Now, we will create a simple application/program along the lines of a Hello World program to make sure the environment is set up correctly, while explaining some of the initial features of the IDE as we go.

Getting ready

You should have already started the assimilation process by completing the recipe First contact – installing Ruby and RubyMine (Must know). If not, go back and restart the assimilation process.

How to do it...

When starting to learn a new language, it is customary to say hello, so let's get started:

  1. Open RubyMine and you will be presented with the Welcome to JetBrains RubyMine window:

  2. Select the option Create New Project.

  3. Use the name HelloWorld in the first box and leave the other two options as default. We are going to start with a simple Ruby application, even though RubyMine can create many different types of project such as a Ruby on Rails project and Twitter Bootstrap Web project.

  4. Your next task is to create a new Ruby file that we can use to begin building our first program.

  5. Navigate to File | New … and you will be presented with a list of various choices of files to create.

  6. Choose the File item, which is simply a Ruby file.

  7. Name it helloworld.rb. Don't forget the .rb extension, as this is necessary to distinguish it from a simple text file, which it really is anyway.

  8. Now, type in the following program into this new document that you created:

    puts "Hello Biological Life Form. We are the Borg."
    puts "We will add your biological and technological distinctiveness to our own."
    puts "Resistance is futile."

This is your first Ruby program in RubyMine! Let's run it using the following steps and see what happens:

  1. Navigate to Run | Run and you will see a window similar to this:

  2. Select the helloworld configuration and it will execute your first Ruby script. The output of your program should then be shown in a window panel below your helloworld.rb file. Each puts command prints out the string to the console and appends a carriage return to the end automatically. RubyMine captures this output in the window at the bottom of the program.

You have successfully begun your assimilation into the collective—there is no stopping you now.

How it works...

RubyMine keeps everything inside its various panels so that you don't have to keep switching between your editor, a terminal/console window, and your browser. It lets you see the output of your programs in the Run panel at the bottom of the window, so you can compare the output with what you expected your code to do.

When the main project window opens, you will see a Tip of the Day window, similar to the following screenshot:

I highly recommend that you maintain this tip window while you are processed through the assimilation stage, as it is much easier to learn a few things a day rather than everything all at once. Your internal Borg buffers will overflow otherwise.

With the Borg it is all about efficiency so that assimilation can happen that much quicker.

There's more...

Each time you create a new project or run a specific file, a new configuration is created so that it is easier to switch between running tests, Rails development, or simply a Ruby program file. Once a configuration is created, it is available in a pull-down menu at the top, as shown in the following screenshot:

When you select a particular configuration, you can then just hit the green arrow button to run or the green button with a bug on it to debug the files in that configuration.

If you want to run a different configuration, just select it from the menu and hit the green arrow. This makes it more efficient to switch between different files or environments.

Possible errors during execution

If you get any errors while running, first check to see that you entered exactly what is in the preceding program. If you still have errors, it might be your Ruby installation and what RubyMine thinks is your Ruby installation. To check that, select the Settings menu item (Mac OS X it is the preferences item in the RubyMine menu, on Windows and Linux it is the Settings command from the File menu).

This is the main window for setting all of the hundreds of attributes of your RubyMine software.

Select the item Ruby SDK and Gems from the left side of this window. You will then be able to select which version of Ruby that you want RubyMine to utilize for your programs.

Once you have selected a version of Ruby, you must then hit the Apply button at the bottom of this window on the right. You can also install a new version of Ruby here and install and manage the Gems needed for your various projects. A Gem is a standard way of distributing libraries of Ruby code for sharing among developers and projects.

The "Has_Many" options in RubyMine

While you are at the Settings window, go ahead and explore around and select the various items on the left to see what options are available to you. You are provided with a large number of ways to customize and change how your new assimilated tool will work for you and the common good of the collective.