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)

Manipulating your tech (Become an expert)


This recipe will show you how to start the Rails console and inspect your code and database interactively.

Getting ready

Open your Progeny Rails project in RubyMine.

How to do it...

RubyMine allows you to run both the Interactive RuBy (IRB) console as well as the Ruby on Rails console. They both run in an interactive window at the bottom of your editor much like the debugger and output windows. Perform the following steps:

  1. On the Tools menu, select Run Rails Console and RubyMine will ask you which environment you would like to load into the console. This lets you inspect/change your debug, test, or production environments directly. The default option gives the development environment.

  2. Select OK and the console will open.

    The Rails console prompt >> means that it is ready for input from the keyboard.

    Type 2 + 2 and hit Return. The result should be 4 as you can see in the following screenshot. This is just like the IRB console, in that you can type Ruby expressions and they will be evaluated interactively.

  3. Let's perform some database lookups using Rails syntax.

  4. The proper syntax for Rails 4.0 is something like the following, which you can type in and see the result:

    Species.where(assimilated: true).load

    The result will be something like this:

      Species Load (0.2ms)  SELECT "species".* FROM "species" WHERE "species"."assimilated" = 't'
    #<ActiveRecord::Relation [#<Species id: 3, name: "Human", identification: 5618, assimilated: true, created_at: "2013-06-03 00:58:57", updated_at: "2013-06-03 00:58:57">]>

How it works…

We can see that the console returned an array of Species objects that matched that query. It even showed us the SQL query that was used to get the data directly from the database.

There are many wonderful tutorials and tricks online that we can make use of to learn more about the console, starting with the official Rails Guides: http://guides.rubyonrails.org/.