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)

Deploying your progeny to expand your empire (Become an expert)


We will now venture into configuring and using the built-in deployment tools in RubyMine. This is the final step in completing your journey through assimilation and ensures the survival of your species. Deployment can be done in many different ways, but we only have time to explore one.

Getting ready

Open your Progeny Rails project that we created earlier in RubyMine. Make sure that you have a remote location that will accept a Ruby on Rails project and allows SFTP uploading to this site.

How to do it...

RubyMine can interface directly with a remote server and upload/download files to this site, keeping the files in sync automatically. It also has built-in support for the Capistrano deployment Gem to help with this process of remotely deploying and restarting Rails apps.

It is best practice to use our version control system to deploy our application. It is also easiest if we utilize one of the services out on the Internet to house our repository for us during this process. We will add our existing Git repository that we created in the recipe, Ensuring your legacy (Become an expert), to the GitHub system at http://github.com using the following steps:

  1. Navigate to VCS | Import into Version Control | Share Project on GitHub.

  2. This will bring up a window asking for your GitHub account and giving you the opportunity to create one if you don't have one, as you can see in the following screenshot. GitHub is free if you keep your project public and open source, but they also have paid options if that is unappealing to you.

  3. After you log in with a valid account, the next window that appears will be for you to name your project and give it a short description. Doing this will create the remote repository on GitHub for us to use later.

  4. If we now log in to the GitHub account and navigate to your project, you can copy the Git repository URL, as you can see in the following screenshot, which we can add to our deploy.rb file for use in Capistrano:

  5. Now, we need to install the Capistrano Gem by adding it to our Gemfile as we have done before, except this time Rails knows that this is a common Gem, so we just need to uncomment out the line in the Gemfile like the following:

    # Use Capistrano for deployment
     gem 'capistrano', group: :development
    
  6. Navigate to Tools | Bundle | Install.

  7. Now we can use RubyMine tools to start the Capistrano process. We must first navigate to Tools | Capistrano | Capify Application.

  8. This will create two files: Capfile and config/deploy.rb.

  9. Open the Capfile file and uncomment out the following line so that the process will run the precompilation of the assets pipeline after deploying the files to your webserver:

    load 'deploy/assets'
  10. Open the config/deploy.rb file and edit the following lines using the GitHub repository URL that you copied from your account for the :repository line:

    require 'capistrano-deploy'
    
    set :application, "progeny"
    set :repository, "https://github.com/lockersoft/Progeny.git"
    set :user, "lockersoft"
  11. Of course, you would use your own specific information for the server where you are going to deploy your application. There are many different options that you can use from Capistrano to customize your deployment to meet a variety of needs for your particular collective. Too many to show here, so start by looking at the Capistrano Gem documentation found at https://github.com/capistrano/capistrano.

  12. Once we have our deploy.rb file the way we want it, we can commit our changes and push those changes to the GitHub remote repository that we created earlier. Navigate to VCS | Commit Changes.

  13. This will bring up a window that we saw earlier where we can add a message to our commit. At the bottom of the window, instead of selecting Commit, we want to select the option Commit and Push...:

  14. This will bring one final window which allows us to choose a different branch. Just hit the Push button and our project will be uploaded to the GitHub repository.

  15. Now, we are ready to deploy the project. We will let Capistrano do that for us by merely running that script. Navigate to Tools | Capistrano | Run Capistrano, which will bring a window to allow us to select one of many tasks to run. The first one we want to run is the deploy:setup command. This runs much like the rake tasks and once we select and run a task, it is saved in our task configuration menu at the top of the main project for later use, as shown in the following screenshot:

    This will create the directory structure that Capistrano needs on your remote server for us.

  16. The next Capistrano command is selected from the same menu, but it is simply deploy. This will actually issue a command on the remote server to clone our Git repository from GitHub into our remote server directory and we will now be ready to access our server.

  17. If everything is right in our deploy.rb script, which is saying a lot, then the Rails server will be running on our remote server and we can simply connect to the server via a browser like one of our users would.

How it works…

Now, whenever we need to make a change to our application, we just have to follow the following steps in order to deploy those changes:

  • Commit and push our changes to the remote GitHub account

  • Run the Capistrano deploy task

  • Check the server with our browser to make sure everything is working as we expect

We have now successfully deployed our application, which in turn can spawn new drones in our quest for perfection for our entire collective.

There's more…

There are many video tutorials that I have created from my lectures in teaching Ruby, Ruby on Rails, Mobile Development, Java and Android Development, and even PHP development on my YouTube channel. For lectures on all of these, I use the Jetbrains tools such as RubyMine, PHPStorm, and IntelliJ. Check them out at http://youtube.com/lockersoft.

In addition, some of the source code examples and code from my other lectures can be found on my GitHub account at https://github.com/lockersoft.