





















































(For more resources related to this topic, see here.)
Now, we will learn how to utilize RubyMine to manage your Gems and external libraries used for your Ruby on Rails programs.
Start RubyMine and open the HelloWorld project that we created earlier. We will be adding an implant to enhance your assimilation process into the collective.
We will now use a Gem in RubyMine by showing the following simple example using the Prawn Gem:
require 'prawn' Prawn::Document.generate("hello.pdf") do |pdf| pdf.font "Courier" pdf.stroke_color = "ff0000" pdf.line_width = 5 pdf.stroke do pdf.circle([300, 300], 100); pdf.circle([350, 320], 20); pdf.circle([260, 325], 20); pdf.curve [270, 250], [340, 250], :bounds => [[270, 270],[275, 220]] end pdf.move_down(300) pdf.font_size = 36 pdf.fill_color "000000" pdf.draw_text("You will be assimilated!", :at => [40, 40]) pdf.line_width = 1 pdf.stroke_color = "0000ff" pdf.move_to([0, 0]) grid = 11 num_lines = 51 size = (num_lines - 1) * grid pdf.stroke do 51.times do |idx| pdf.line([0, idx*grid], [size, idx*grid]) pdf.line([idx*grid, 0], [idx*grid, size]) end end end
This will synchronize the files inside the folder with the project list. You should now be able to see the file hello.pdf in the project window.
The code that we typed in is a simple use of the Prawn Gem. It first requires the Gem code and then starts a block of code that will begin generating the hello.pdf file on the disk. Each command then sets properties of the text, size, colors, circles, and finally draws a grid of lines on the page.
Now it is time to create and run a simple Ruby on Rails application using RubyMine exclusively.
Open RubyMine and navigate to File | New Project. From this window, you can now select what type of project to begin with. RubyMine gives you several options that you can use later. Right now, select Rails application, as shown in the following screenshot:
Hit OK and you will see the next settings window which allows you to select which version of Rails you would like to use in your project, along with the JavaScript library and database configurations.
Select the checkbox for Preconfigure for selected database and choose the sqlite3 option, as shown in the following screenshot. Leave the rest as default and hit OK.
Now that you have created a new Rails project, RubyMine takes over and starts using Rails to generate all of the files and configuration necessary for a complete project, including running the command bundle install at the end. This will make sure that you have all the proper Gems installed for your Rails project.
Now, we can run what we have and see that everything is installed correctly, using the following steps:
Now, we can build some features for our app. Let's begin by creating an interface to our database of species that we have already assimilated. For this, we can use the Rails generators to build the scaffolding of our application that gives us something to build on.
All of the functionalities of Rails can be accessed from within the RubyMine environment, as shown in the following steps, so it is not necessary to go out to a command window at all:
The following window gives us the opportunity to name our table and the various fields that it will contain. The database table will become the name of our model as well.
Species name:string identification:integer assimilated:Boolean
Oops! We forgot to do something after creating the code for the database tables. We need to run the migrations that will create the actual tables.
Click on the links and add some species to your database. The scaffolding that we generated, produced all of the CRUD (Create Read Update Delete) forms and screens necessary for managing our Species database table, without typing any commands in our terminal or leaving RubyMine at all.
Of course it has no style, but who cares about style? We are the Borg and only care about technology!
Ok. Maybe we can spruce it up a little bit. Lets add a Gem called Bourbon that helps with the following:
gem 'bourbon'
Now we need to install the Gem by running bundle install. We can do this directly from RubyMine by navigating to Tools | Bundler | Install.
@import "bourbon"; p { @include linear-gradient(to top, white, steelblue); }
Once complete, look at the configuration menu and you will notice that you now have some additional commands in this shortcut menu. RubyMine remembers the tasks and commands that you have executed for you to make it more efficient, as you will likely be running these commands often.
This is a technology that is worthy of assimilating to its fullest extent. In this article we covered Managing your implants and Creating your first progeny, which shows create and run a simple Ruby on Rails application using RubyMine.
Further resources on this subject: