Last updated 20 April 2015
All about Ruby on Rails 4.2 on the Nitrous.io hosted development environment.
With detailed instructions for getting started on Nitrous.io with Rails including advice to get you fully productive.
If you’re new to Rails, see What is Ruby on Rails?, the book Learn Ruby on Rails, and recommendations for a Rails tutorial.
This is an article from the RailsApps project. The RailsApps project provides example applications that developers use as starter apps. Hundreds of developers use the apps, report problems as they arise, and propose solutions. Rails changes frequently; each application is known to work and serves as your personal “reference implementation.” Support for the project comes from subscribers. If this article is useful to you, please accept our invitation to join the RailsApps project.
Nitrous.io provides a hosted development environment. Simply put, you get access to a remote computer from your web browser.
The Nitrous computer runs Ubuntu Linux, a popular operating system for Rails development. The online computer is instantly created with everything in place to immediately begin working on projects in Rails. This guide will orient you and provide additional details so you can be productive with Rails.
There is no cost to set up an account. You will only be charged if you decide to add extra storage or memory.
For ordinary Rails development, you don’t need extra storage or memory. For typical projects, the Nitrous.io service is free.
Like other companies that offer basic services for free (such as Heroku for Rails hosting), Nitrous.io hopes that full-featured free service will lead to popularity and revenues from upgrades. This approach greatly benefits anyone who needs to keep expenses low, especially startup founders, students, and developers in the world’s emerging economies.
The Nitrous.io service gives you everything you need for Rails development, including:
For pair programming or other collaboration:
If you want to use your own Terminal application:
Additionally, with Nitrous Desktop:
The Nitrous.io service offers enormous value. However, these limitations may make it unsuitable for you:
If you need root access to install a package, you can ask Nitrous support to do it.
In principle, Nitrous.io allows you to do Rails development from any device that runs a web browser, including a tablet or smartphone. However, to be productive:
Like any other Rails development environment:
Nitrous.io can be used on any operating system that provides a web browser and an Internet connection.
As an alternative to installing Ruby directly on your own computer, Nitrous.io can be beneficial:
Developers who travel frequently, or work at multiple sites, like cloud-based development because any computer provides access to a fully-configured, productive development environment. Additionally, cloud-based development means you will remain productive if your laptop is lost, stolen, or fails in service.
Most Macintosh users will prefer to install Ruby on Rails on Mac OS X directly. However, Nitrous.io can be beneficial for the reasons listed above. You can use your favorite Mac OS X text editor such as Sublime Text or Textmate to edit files on the Nitrous servers so Nitrous.io primarily gives you a cloud-based shell and file storage.
The Nitrous.io shell environment will be familiar to any Ubuntu Linux user. Unlike Linux virtual private servers from companies such as Linode, you won’t get root access and you can’t do your own system administration. However, the Nitrous.io service is free and the system is maintained for you so you’ll spend more time as a developer and less time as a sysadmin. Nitrous.io is particularly appropriate for newcomers who want to learn Unix but might be overwhelmed by the effort required to install and confgure Ubuntu Linux.
Installing Rails on Windows is frustrating and painful. I often hear that students have given up on learning Rails because installation of Ruby on Windows is difficult and introduces bugs or creates configuration issues. Even when you succeed in getting Rails to run on Windows, you will encounter gems you cannot install. For these reasons, Nitrous.io is an ideal option for a Rails development environment on a Windows laptop. You will have to use the Nitrous browser-based text editor, as there is no option to use Sublime Text or other Windows text editors. If you are an expert with the Windows PowerShell or other terminal applications, you can SSH to the Nitrous shell as an alternative to using the Nitrous browser-based console.
A Chromebook is a personal computer running the Google Chrome OS operating system. Chromebooks are among the least expensive laptops available, selling for as low as $200 (US). Chromebooks are intended for cloud-based computing with no local storage and all applications running in the web browser. As such, Nitrous.io is ideally matched to Chromebooks. At $200 (US), a Chromebook with Nitrous.io is probably the least expensive way for a student to get a fully functional Rails development environment.
Nitrous.io gives you enough memory and file storage to develop one or more moderately-complex Rails applications.
If you want more than one virtual computer, or you want to add memory and more file storage, you can purchase additional capacity. The company sells credits they call “N2O” which can be used to increase capacity.
All accounts come with 155 N2O credits, enough for a starter box, for free.
The company will give you additional N2O for free if you help expand their customer base by inviting friends or social sharing with Twitter.
The company makes money by providing extra memory and file storage.
You may find that 750MB of storage is not enough for all your Rails applications. If you’re cloning repositories from your own GitHub account, you may need to rotate projects on and off your Nitrous box to fit the available storage. If that’s inconvenient, purchase more N2O and increase your storage capacity so you can keep a copy of all your repositories on your Nitrous box.
A compelling reason for purchasing an additional Nitrous box is to configure a second development environment. If you want to restrict sharing and collaboration to certain projects, and not allow your pairing partners access to all your projects, you may need a second box.
You may want to set up a second box for testing with a different configuration. More commonly, you’ll use RVM or another Ruby environment manager such as Chruby or Rbenv to switch among different versions of Ruby on just one box. You could purchase a second box to run a different version of Ruby. More likely, you’d purchase a second box to experiment or troubleshoot issues with your shell environment.
See the Nitrous.io pricing page to determine how much you’ll spend for additional capacity.
Visit the Nitrous.io website to sign up. You can create an account using your own email address and password or you can establish an account using your GitHub, Google, or LinkedIn account.
There is no cost to set up an account.
After you establish an account and sign in, you’ll see a button “Open Dashboard.” Click the button to get started.
A Nitrous “box” is a virtual computer. You get one for free, with 384MB of memory and 750MB of storage, which is enough to build and run one or more Rails applications.
To create a box, click the “Boxes” link in the navigation bar. Then click the “New Box” button.
Make sure you’ve selected “Ruby/Rails”.
Enter a name for your box. Call it “ruby-uswest” or something else that shows the region and development enviornment you’ll use. Of course, if you prefer, you can give your box a clever pet name like “dragons-be-here.”
Select a region. For maximum speed and reduced network latency, use the region that is geographically closest to your Internet Service Provider.
You’ll get 155 N2O credits when you set up your account. You get an additional 5 N2O for confirming your email. If you’ve been given more, you can apply the credits to increase your storage capacity. With 160 credits, you can increase your storage from the minimum 750MB to 1GB.
Click the “Create Box” button and Nitrous will build your virtual computer in a few seconds.
See the Nitrous Creating a Box documentation for more.
As soon as you’ve built a new box, you’ll see the Web IDE (Integrated Development Environment).
You can find your way back to the Web IDE by visiting the “Boxes” page, clicking the box name, and clicking the “IDE” button.
The Nitrous.io navigation bar is simple, with just a few menu items. The Nitrous Web IDE is much more complex, because it is a full development environment that does the duty of a console, a file browser, a text editor, and a chat room.
Here’s the Web IDE for a new box.
Take time to get familiar with the interface. For example:
Close the chat window (unless you are going to collaborate).
Drag the bar at the top of the console window to resize it. You’ll often need a bigger console window.
Click the icon to expand or minimize the console window. You’ll often need a full console window.
Click the “plus” icon to open a tab for a second console window. You’ll often need multiple console windows. For example, you might leave a Rails server running in one console while entering Rails commands in another.
See the Nitrous Getting Started with the WebIDE for more.
Let’s use the console to explore the Nitrous workspace and create a Rails application.
If you haven’t used the Unix command line interface (CLI) before, spend some time with The Command Line Crash Course to become comfortable with Unix shell commands.
Expand the console window and use Unix commands to explore the directory structure:
action@ruby-uswest-21609:~$ pwd /home/action action@ruby-uswest-21609:~$ echo $SHELL /bin/bash action@ruby-uswest-21609:~$ ls -la total 68 drwxr-xr-x 7 action action 4096 Aug 5 23:45 . drwxr-xr-x 4 root root 4096 Aug 5 23:45 .. -rw-r--r-- 1 action action 116 May 2 10:42 .bash_profile -rw-r--r-- 1 action action 631 May 2 10:42 .bashrc drwx------ 2 action action 4096 Aug 5 23:45 .cache drwxrwxr-x 4 action action 4096 May 2 10:28 .gem -rw-r--r-- 1 action action 76 May 2 10:41 .gemrc -rw-r--r-- 1 action action 134 May 2 10:41 .gitconfig -rw-r--r-- 1 action action 520 Aug 5 23:45 .nitrousboxrc.sample -rw-r--r-- 1 action action 55 May 22 19:07 .pam_environment drwxrwxr-x 15 action action 4096 Aug 5 23:45 .parts -rw-r--r-- 1 action action 2464 Aug 5 23:45 README.md -rw-rw-r-- 1 action action 10 May 2 10:42 .ruby-version drwxr-xr-x 2 action action 4096 Aug 5 23:45 .ssh -rw-r--r-- 1 action action 88 May 2 10:41 .tmux.conf -rw-r--r-- 1 action action 26 May 2 12:20 .VERSION drwxr-xr-x 2 action action 4096 Aug 5 23:45 workspace
The user home directory is home/action/. The Unix command cd ~
always takes you back here.
The Unix command echo $SHELL
shows you that you are using the Bash shell.
The ls -la
command lists all the hidden files and folders.
If you have some experience with a Unix environment or Rails, you’ll recognize configuration files for some familiar tools:
You’ll see that Nitrous.io has set an informative Unix command prompt for your shell:
action@ruby-uswest-21609:~$ whoami action
“Action” is the username for any Nitrous user. The virtual computer name is shown, as well as the current directory, followed by the familar $
Unix command prompt.
For brevity, for the rest of this tutorial, I’ll show the command prompt as simple $
.
When your box is created, there is one directory named workspace/.
$ pwd /home/action $ ls README.md workspace
It is important to create your projects inside this folder.
If you use the Nitrous client application for Mac OS X, the user home directory will not be available in your Mac filesystem. The workspace/ folder is mounted in your Mac filesystem so you can edit files directly with a text editor such as Sublime Text. If you put projects in the user home directory, you will not be able to edit them directly on your Mac OS X computer.
The Nitrous box includes a pre-installed version of chruby, a tool to switch Ruby versions. Chruby doesn’t install new Ruby versions or manage sets of gems; for that, I recommend RVM, the Ruby Version Manager. As new versions of Ruby are released, you’ll need an easy way to switch between versions. I recommend RVM to manage your Ruby versions because it is popular, well-supported, and full-featured.
Remove chruby by using the “Autoparts/Manage Packages” menu item. Click the box to “Show only installed packages.”
It takes a few minutes to uninstall Ruby.
Close and reopen the console window.
A old “system version” of Ruby is still available:
$ ruby -v ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-linux]
We’ll leave it in place and use RVM to install the newest version of Ruby.
Use RVM, the Ruby Version Manager, to install Ruby and manage your Rails versions.
RVM will leave the “system Ruby” untouched and use your shell to intercept any calls to Ruby. There’s no need to remove it. The “system Ruby” will remain on your system and the RVM version will take precedence.
Ruby 2.2.2 was current when this was written. You can check for the current recommended version of Ruby. RVM will install the newest stable Ruby version.
The RVM website explains how to install RVM. Here’s the simplest way:
$ \curl -L https://get.rvm.io | bash -s stable --auto-dotfiles --ruby
Note the backslash before “curl” (this avoids potential version conflicts).
The “—ruby” flag will install the newest version of Ruby.
Activate RVM in the console:
$ source /home/action/.rvm/scripts/rvm
Test if RVM is available:
$ rvm -v rvm 1.25.28 (stable) by ...
If you have trouble installing Ruby with RVM, you can get help directly from the RVM team using the IRC (Internet Relay Chat) channel #rvm on irc.freenode.net:
http://webchat.freenode.net/?channels=rvm
If you’ve never used IRC, it’s worthwhile to figure out how to use IRC because the RVM team is helpful and friendly. IRC on freenode requires registration (see how to register).
The newest version of Ruby is now installed:
$ ruby -v ruby 2.2.2p... (2014-05-08 revision 45877) [x86_64-linux]
Ruby 2.2.2 was current when this was written. You can check for the current recommended version of Ruby.
If you need an older version of Ruby, you can install it with RVM:
$ rvm install 1.9.3
Check which Ruby versions are installed:
$ rvm list rvm rubies =* ruby-2.2.2 [ x86_64 ] # => - current # =* - current && default # * - default
RubyGems is the gem manager in Ruby.
Check the installed gem manager version:
$ gem -v 2.2.2
You should have:
At the time this was written, a newer RubyGems 2.4.1 version was available. Don’t install the newer version. A bug prevents installing the newest Rails pre-release version (see Rails issue 16609) if you use RubyGems 2.4.1.
In the future, when the bug is resolved, you can use gem update --system
to upgrade the Ruby gem manager.
Not all Rails developers use RVM to manage gems, but many recommend it.
Display a list of gemsets:
$ rvm gemset list gemsets for ruby-2.2.2 => (default) global
Only the “default” and “global” gemsets are pre-installed.
If you get an error “rvm is not a function,” close your console and open it again.
See what gems are installed in the “global” gemset:
$ rvm gemset use global $ gem list
A trouble-free development environment requires the newest versions of the default gems.
Several gems are installed with Ruby or the RVM default gemset:
To get a list of gems that are outdated:
$ gem outdated ### list not shown for brevity
To update all stale gems:
$ gem update ### list not shown for brevity
In particular, rake should be updated to version 10.2.1 or newer.
You can track updates to gems at the RubyGems.org site by creating an account and visiting your dashboard. Search for each gem you use and “subscribe” to see a feed of updates in the dashboard (an RSS feed is available from the dashboard). After you’ve built an application and set up a GitHub repository, you can stay informed with Gemnasium or VersionEye. These services survey your GitHub repo and send email notifications when gem versions change. Gemnasium and VersionEye are free for public repositories with a premium plan for private repositories.
By default, when you install gems, documentation files will be installed. Developers seldom use gem documentation files (they’ll browse the web instead). Installing gem documentation files takes time, so many developers like to toggle the default so no documentation is installed.
Here’s how to speed up gem installation by disabling the documentation step:
$ echo "gem: --no-document" >> ~/.gemrc
This adds the line gem: --no-document
to the hidden .gemrc file in your home directory.
The Bundler gem is an essential tool for managing gems when developing and running Rails applications. RVM used to install Bundler automatically. As of version 1.26.11 (released March 31, 2015), RVM no longer installs Bundler automatically. You must install Bundler:
$ gem install bundler
Nokogiri is a gem that is a dependency for many other gems. Nokogiri is a gem that requires compilation for your specific operating system. As such, if your system environment doesn’t match Nokogiri’s requirements, compilation of Nokogiri will fail. If your system is configured properly, you’ll be able to compile Nokogiri. However, compilation takes time. Every time you install the Nokogiri gem, you’ll wait (as long as five minutes).
To save time, install the Nokogiri gem in the RVM global gemset:
$ gem install nokogiri
During installation, Nokogiri will display two lengthy messages in the console. It will also pause without displaying any progress for as long as five minutes. Don’t assume installation has failed unless you see an error message or you’ve waited more than ten minutes.
If installation fails, make sure your system is configured properly (look for help on Stack Overflow).
Check for the current version of Rails. Rails 4.2.1 was current when this was written.
You can install Rails directly into the global gemset. However, many developers prefer to keep the global gemset sparse and install Rails into project-specific gemsets, so each project has the appropriate version of Rails.
If you install Rails at this point, you will install it into the global gemset.
Instead, make a gemset just for the current stable release:
$ rvm use ruby-2.2.2@rails4.2 --create
Here are the options you have for installing Rails.
If you want the most recent stable release:
$ gem install rails $ rails -v
If you want the newest beta version or release candidate, you can install with --pre
.
$ gem install rails --pre $ rails -v
Or you can get a specific version.
For example, if you want the Rails 3.2.18 release:
$ gem install rails --version=3.2.18 $ rails -v
First, change directories into the action/workspace/ folder:
$ cd workspace
It’s best to create all your Rails applications in this action/workspace/ folder.
Here’s how to create a project-specific gemset, installing Rails, and creating a new application.
$ mkdir myapp $ cd myapp $ rvm use ruby-2.2.2@myapp --ruby-version --create $ gem install rails $ rails new .
We’ll name the new application “myapp.” Obviously, you can give it any name you like.
With this workflow, you’ll first create a root directory for your application, then move into the new directory.
With one command you’ll create a new project-specific gemset. The option “—ruby-version” creates .ruby-version and .ruby-gemset files in the root directory. RVM recognizes these files in an application’s root directory and loads the required version of Ruby and the correct gemset whenever you enter the directory.
When we create the gemset, it will be empty (though it inherits use of all the gems in the global gemset). We immediately install Rails. The command gem install rails
installs the most recent release of Rails.
Finally we run rails new .
. We use the Unix “dot” convention to refer to the current directory. This assigns the name of the directory to the new application.
This approach is different from the way most beginners are taught to create a Rails application. Most instructions suggest using rails new myapp
to generate a new application and then enter the directory to begin work. Our approach makes it easy to create a project-specific gemset and install Rails before the application is created.
The rails new
command generates the default Rails starter app. If you wish, you can use the Rails Composer tool to generate a starter application with a choice of basic features and popular gems.
For a “smoke test” to see if everything runs, display a list of Rake tasks.
$ rake -T
There’s no need to run bundle exec rake
instead of rake
when you are using RVM (see RVM and bundler integration).
You can launch and run the application with the Rails server:
$ rails server
Let’s take a closer look at the Web IDE now that we have created a Rails application.
Here’s the Web IDE after we’ve created a Rails application and launched the Rails server.
A single console window is open, running the Rails server, and showing server log messages.
In the file browser, we’ve expanded the folder hierarchy and selected the application Gemfile.
The Gemfile is open in the text editor.
This is everything we need to develop a Rails application, except a browser to show us the application.
Select “Preview” in the navigation bar.
Select “Port 3000” in the Preview menu.
A new browser tab will open displaying the application.
This is the default Rails starter application.
You can stop the server with Control-c to return to the command prompt.
Most of the time you’ll keep the web server running as you add or edit files in your project. This a reason to open multiple console windows.
Changes will automatically appear when you refresh the browser or request a new page. There is a tricky exception, however. If you make changes to the Gemfile, or changes to configuration files, the web server must be shut down and relaunched for changes to be activated.
Working on a remote server means you can lose a connection (or close your console window) while the server is still running. If that happens, you may find you cannot start the server because you get an error, “A server is already running.” Use the provided PID file to find the Unix process ID and then stop the server with the Unix kill -9 PID
command.
$ rails server . . . A server is already running. Check /home/action/workspace/myapp/tmp/pids/server.pid. Exiting $ cat /home/action/workspace/myapp/tmp/pids/server.pid 4640 $ kill -9 4640
The Unix kill -9
command will stop the abandoned server process. If not, go to “Boxes” in the Web IDE and use the button to restart your Nitrous box.
Git is an essential tool for developing with Rails. With Git, you can roll back code changes as needed, collaborate on code with others, and deploy your application for hosting on Heroku. See the article Rails with Git and GitHub for more information.
Git is pre-installed on your Nitrous box. Check that Git is installed:
$ git version git version 2.0.0
You must configure Git before you can use it:
$ git config --global user.name "Real Name" $ git config --global user.email "me@example.com"
Use your real name so people will associate you with your work when they meet you in real life. There’s no reason to use a clever name unless you have something to hide. Here’s another tip: Life will be easier if you use the same email address for Git, your GitHub account, and Heroku.
Check that Git is configured correctly:
$ git config -l --global . . . user.name=Real Name user.email=me@example.com
Rails developers use GitHub, the “social coding” website, for collaboration and remote backup of projects. GitHub is absolutely essential to all open source Rails development (and most proprietary development as well). Get a free personal GitHub account if you don’t already have one.
There are two ways to “clone” (download) project repositories from GitHub. GitHub suggests using the https
protocol because it works even when you are behind a firewall. On a Mac, you can set up Git so you don’t have to enter a username and password when you “push” (upload) your changes to GitHub. With https
on Linux, you’ll have to enter your username and password each time.
For greater convenience, use the git
protocol when you clone a GitHub repository. On a GitHub project page, look for the tiny text, “You can clone with HTTPS, SSH, Subversion, and other methods” and choose SSH.
To avoid entering your username and password every time you push to GitHub, set up SSH keys to establish a secure connection between your Nitrous box and GitHub.
Nitrous has already created an SSH public key for you. View it with the Unix cat
command:
$ cat ~/.ssh/id_rsa.pub ssh-rsa 094fa31ab0 ... deafdc0d== root@usw1-2.nitrousbox.com
Carefully copy the entire string (it’s longer than the example shown here).
Log in to your GitHub and go to “Account Settings” (the tiny wrench and screwdriver at the upper right corner of any page).
Select “SSH Keys” in the left sidebar. Click “Add SSH key”.
Enter any helpful name in the “Title” field, such as “nitrous-ruby-uswest”.
Carefully paste your key into the “Key” field.
Click the “Add key” button. Confirm the action by entering your GitHub password.
Check that your GitHub account is set up properly. Enter “yes” when prompted to continue.
$ ssh -T -p 443 git@ssh.github.com The authenticity of host '[ssh.github.com]:443 ([192.30.252.149]:443)' can't be established. RSA key fingerprint is 16:27:ac:a ... df:a6:48. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '[ssh.github.com]:443,[192.30.252.149]:443' (RSA) to the list of known hosts. Hi DanielKehoe! You've successfully authenticated, but GitHub does not provide shell access.
The command establishes a secure SSH connection from your Nitrous box to port 443 on the GitHub server. The first time you connect, your Nitrous box will warn you that it has never connected to the server and can’t be sure the host is legitimate and secure. Unless you are a target of a sophisticated hacking scheme, you can safely answer “yes” when prompted.
If your SSH key is set at your GitHub account, the GitHub server will confirm you’ve successfully connected and inform you that “GitHub does not provide shell access.” That just means you can’t log in to GitHub and use their servers the way you are using your Nitrous box as your personal console. That’s fine; GitHub is not used for remote shell services.
With SSH keys saved to your GitHub account, you can use GitHub without entering your username and password every time you push.
Nitrous provides a fully functional text editor within the Web IDE browser. You can use it from any computer, whether Mac, Linux, Windows. If you prefer the Vim text editor, or Emacs, you can use your console to edit text.
Mac OS X users who prefer full-featured text editors such as Sublime Text or Textmate can download and install Nitrous Desktop.
The Nitrous Desktop application works like Dropbox, the file hosting service. A folder in your Mac filesystem contains a copy of all the folders and files in the workspace/ folder of your Nitrous box and automatically synchronizes the files. This means that any application on your Mac can manipulate the files stored on your Nitrous box. And not just text editors; you can use full-featured applications such as Eclipse or RubyMine, or any other application you like.
Start by downloading the Nitrous Desktop application. After installing the application, it will ask where to mount the Nitrous workspace/ folder. You can set your Nitrous username and password and generate and register SSH keys to set up a secure connection to your Nitrous box.
The Nitrous application is available from your Mac OS X menu bar. You’ll see a listing for your Nitrous box (such as “ruby-uswest”). You can launch the Mac Terminal application from the Nitrous application to access your Nitrous box shell. Or you can launch the Web IDE from the Nitrous application menu.
In your Mac OS X home directory, you’ll find a Nitrous.io/ folder. All the files from your Nitrous box are there.
Just drag the files from your Mac Finder to your text editor. Or use your text editor to open the files directly.
As you make changes and save a file, you’ll see a brief notification that your files are being synchronized with the Nitrous box.
In many ways, this is the best of all worlds. Your project files are backed up to your Nitrous box (where you can commit changes to GitHub), and you’ll use your Nitrous box to run your applications, so you are working “in the cloud.” But you can use a native Mac text editor with full mouse and keyboard support.
See the Nitrous Nitrous Desktop documentation for more information.
Just as you can use your favorite text editor (on Mac OS X only), you can use your favorite Terminal application to connect to the shell running on your Nitrous box (from Linux, Mac, or Windows). This is primarily an option for experienced users; the Web IDE console is fine for beginners. See the Nitrous Adding SSH keys documentation for more information.
Experienced Unix users often configure the shell with a fancy prompt, environment variables, and command aliases. You can switch to the Z shell and install Robby Russell’s oh-my-zsh for the ultimate power user experience (experts only!).
Bash-it is a simpler alternative to oh-my-zsh if you want to continue to use the Bash shell. It’s easy to install if you just want a fancy prompt and a library of command aliases.
$ git clone git@github.com:revans/bash-it.git .bash_it $ ~/.bash_it/install.sh
During the initial install, choose “none” for each prompt to avoid installing more than you need. You can run bash-it show aliases
later to pick command aliases for the tools you use.
Close and reopen the console to enable Bash-it and see your new prompt. Bash-it offers a choice of “themes” that give you different prompts.
A fancy prompt will show you the git status of your current directory as well as the current RVM gemset. And, of course, it will impress your friends.
You can use your Nitrous box for pair programming.
Your pairing partner must have a Nitrous account. Begin a pairing session by selecting the “Collaborate” link in the Web IDE navigation bar. To avoid confusion, note that two other navigation bar links, “Connect” and “Invites” are not for collaboration.
“Toggle Chat,” in the “Collaborate” menu, opens and closes the chatroom window. You can text chat with your pairing partner in the chatroom. Messages in the chatroom will display names of files your partner has opened. The name of the file is a link; clicking on the filename is a good way to open the file to begin work together. You must click the tab for “Collab Mode” in the text editor to see your partner typing in the file.
Collaboration is limited to the text editor and the chatroom. Your console windows (and your partner’s console windows) are not shared, so your partner cannot see what you are doing in your console. If you want to share a console, you can run Tmux, a terminal multiplexer, which lets you switch between multiple sessions in one console window, and leave sessions running between logins.
If you are physically present with your partner, at a shared desk or in the same room, Nitrous is a good way to edit a project using two keyboards and two displays.
For remote collaboration, open a browser window for video chat (such as Google Hangouts) or use Skype for conversation. You can screenshare with video chat if your partner needs to see your full screen.
See the Nitrous Collaborative Coding Overview for more information.
The starter application you create with rails new
is very basic.
Use the Rails Composer tool to build a full-featured Rails starter app.
You’ll get a choice of starter applications with basic features and popular gems.
Here’s how to generate a new Rails application using the Rails Composer tool:
Using the conventional approach:
$ rails new myapp -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb
Or, first creating an empty application root directory:
$ mkdir myapp $ cd myapp $ rvm use ruby-2.2.2@myapp --ruby-version --create $ gem install rails $ rails new . -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb
You can add the -T
flags to skip Test::Unit if you are using RSpec for testing.
You can add the -O
flags to skip Active Record if you are using a NoSQL datastore such as MongoDB.
The RailsApps project provides example apps that show how real-world Rails applications are built. Each example is known to work and can serve as your personal “reference implementation”. Each is an open source project. Dozens of developers use the apps, report problems as they arise, and propose solutions as GitHub issues. There is a tutorial for each one so there is no mystery code. Purchasing a subscription for the tutorials gives the project financial support.
Example Applications for Rails 4.2 | Tutorial | Comments |
---|---|---|
Learn Rails | Learn Ruby on Rails | introduction to Rails for beginners |
Rails and Bootstrap | Rails Bootstrap Tutorial | starter app for Rails and Bootstrap |
Rails and Foundation | Rails Foundation Tutorial | starter app for Rails and Zurb Foundation |
Mailing List with Active Job | Mailing List with Active Job Tutorial | background processing |
OmniAuth and Rails | OmniAuth Tutorial | OmniAuth for authentication |
Devise and Rails | Devise Tutorial | Devise for authentication |
Role-Based Authorization | Role-Based Authorization Tutorial | Simple authorization |
Pundit and Rails | Rails Pundit Tutorial | Pundit for authorization |
Sign Up and Download | Sign Up and Download Tutorial | Devise with authorization to download a PDF file |
Stripe Checkout | Stripe Checkout Tutorial | selling a product with Stripe Checkout |
If you’ve already created an application with the command rails new myapp
, you can still create a project-specific gemset. Here’s how to create a gemset for an application named “myapp” and create .ruby-version and .ruby-gemset files in the application’s root directory:
$ rvm use ruby-2.2.2@myapp --ruby-version --create
You’ll need to install Rails and the gems listed in your Gemfile into the new gemset by running:
$ gem install rails $ bundle install
If you have already created both an application and a gemset, but not .ruby-version and .ruby-gemset files, here’s how to add the files. For example, if you want to use an existing gemset named “ruby-2.2.2@myapp”:
$ echo "ruby-2.2.2" > .ruby-version $ echo "myapp" > .ruby-gemset
Using .ruby-version and .ruby-gemset files means you’ll automatically be using the correct Rails and gem version when you switch to your application root directory on your local machine.
Rails uses the SQLite database by default. Your Nitrous box comes with SQLite pre-installed and there’s nothing to configure. With Nitrous Autoparts, you can add various database servers. Nitrous also provides connections to hosted database services. See the Nitrous Databases documentation to set up databases.
Though SQLite is adequate for development (and even some production applications), a new Rails application can be configured for other databases. The command rails new myapp --database=
will show you a list of supported databases.
Supported for preconfiguration are: mysql, oracle, postgresql, sqlite3, frontbase, ibm_db, sqlserver, jdbcmysql, jdbcsqlite3, jdbcpostgresql, jdbc.
For example, to create a new Rails application to use PostgreSQL:
$ rails new myapp --database=postgresql
The --database=postgresql
parameter will add the pg database adapter gem to the Gemfile and create a suitable config/database.yml file.
Don’t use the --database=
argument with the Rails Composer tool. You’ll select a database from a menu instead.
You can use the Nitrous.io platform to host your web application and make it available to anyone. With a paid plan, you can even add a custom domain. However, Nitrous.io recommends that you deploy your application with a “platform as a service” provider such as Heroku.
For easy deployment, use a “platform as a service” provider such as:
For deployment on Heroku, see the article:
If you’ve cloned an application from GitHub that you’ve deployed previously, you’ll need to add a git remote to deploy it from your Nitrous box:
$ heroku git:remote -a myapp Git remote heroku added.
To push your code to Heroku, you’ll need to add SSH keys for your Nitrous box to Heroku:
$ heroku keys:add Found existing public key: /home/action/.ssh/id_rsa.pub Uploading SSH public key /home/action/.ssh/id_rsa.pub... done
You can learn more about Managing Your SSH Keys on Heroku.
By design, Rails encourages practices that avoid common web application vulnerabilities. The Rails security team actively investigates and patches vulnerabilities. If you use the most current version of Rails, you will be protected from known vulnerabilities. See the Ruby On Rails Security Guide for an overview of potential issues and watch the Ruby on Rails Security Mailing List for announcements and discussion.
Rails uses a session store to provide persistence between page requests. The default session store uses cookies. To prevent decoding of cookie data and hijacking a session, Rails encypts cookie data using a secret key. When you create a new Rails application using the rails new
command, a unique secret key is generated and written to the config/initializers/secret_token.rb file. If you’ve generated a Rails application and committed it only to a private GitHub repository, you do not need to change the secret key. However, if you’ve cloned a public GitHub repository or made your application publicly available on GitHub, you must change the secret key when you deploy. The command rake secret
generates a new random secret you can use. The command won’t install the key; you have to copy the key from the console output to the config/initializers/secret_token.rb file. Remember, you should never deploy an application to production that uses a publicly available secret token (obviously, it is not secret if it is public!).
Nitrous.io provides support for users.
You can also find help on Stack Overflow. Your issue may have been encountered and addressed by others.
Daniel Kehoe wrote the article. Thank you to Erik Trautman of the Odin Project for editing and review.
Get the book Learn Ruby on Rails to and join RailsApps if the article was helpful.
Comments
Is this helpful? Your encouragement fuels the project. Please tweet or add a comment. Couldn't get something to work? For the example apps and tutorials, it's best to open an issue on GitHub so we can help you.
comments powered by Disqus