CIS 658

Getting Started with Rails

Winter 2020

Note: Parts of this document were originally written by Prof. Engelsma.

RVM

RVM is the Ruby Version Manager. It allows you to have multiple versions of Ruby installed on your machine. Rails, and certain Ruby packages, can be sensitive to the version. Therefore, I suggest you install and use RVM to manage your Ruby version. (Don't rely on the default Ruby version installed on your machine.)

Platform

Your first decision is whether to install Rails on your own machine, or to run it in a cloud environment. There are advantages to running Rails on your own machine (e.g., you don't have to worry about Internet access or time/space quotas); but, Rails is a complex framework with many dependencies. If you use a cloud platform, it is much easier to start from scratch if anything gets messed up.

Your own machine
Windows
I've never tried installing and running Rails on a Windows machine; but, I've heard it can be painful. If you want to run Rails locally on a Windows machine, try one of these approaches:
Linux or MacOS
There are a number of package installers designed to make this process easier; however, many are out of date, or lag behind hte official version of Rails. As explained above, I suggest using RVM rather than relying on the version of Ruby that came pre-installed on your machine.
  • Install RVM. (See rvm.io for details on your specific platform.)
  • Use RVM to install a recent version of Ruby: rvm install ruby-2.7.0
  • Make the version you just installed your default Ruby interpreter: rvm --default use 2.7.0
  • Install the most recent version of Rails: gem install rails
Cloud Environments
CodeAnywhere
CodeAnywhere is an inexpensive (but not free) Cloud IDE. You can try it for 7 days free. After 7 days, plans start at $3/month.
  • Set up a new CloudAnywhere project and container:
    1. Go to codeanywhere.com/dashboard
    2. Create a new project, then open it.
    3. When you open the new project for the first time, the Connection Wizard will appear. This Connection Wizazrd does two things. (1) You can set up a connection to a source code repository. This step is optional. (2) You name your container and choose its "stack" (initial configuration). Choose the "Ubuntu 16.04" version of Ruby.
    4. Once the container is ready, right click on the container name and select "SSH Terminal".
  • Make sure RVM and Ruby are up-to-date:
    1. Check your RVM version: rvm --version
    2. Upgrade RVM (if desired): rvm get stable
    3. Check your Ruby version: ruby --version
    4. Upgrade Ruby (if desired): rvm install ruby-2.7.0
    5. Set the default Ruby version: rvm --default use 2.7.0
  • Bring Node up-to-date and install yarn. (All Rails apps use at least a little JavaScript. Rails 6.0 manages this JavaScript with a tool called webpack. A recent version of Node and the yarn package manager are needed to install and manage webpack.)
    1. Check the current Node version node -v
    2. Run nvm ls-remote to determine the latest vesion of node. (Currently 12.14.1)
    3. Run nvm install 12.14.1 to install the latest versoin of Node
    4. Run nvm alias default 12.14.1 to set the latest version as the default. (If you don't do this, you'll end up using the old version when you next log in.)
    5. Run npm install -g yarn to install yarn.
  • Finally, we are ready to install Rails and create a new app:
    1. Check the Rails version: rails -v
    2. Install Rails (if necessary): gem install rails --no-document. (This will install rails without the local documentation. If you want the local documentation, run the command above without --no-document.)
    3. Create a new Rails app: rails new name_of_your_app
      • Make sure the current working directory is underneath ~/workspace.
    4. cd into the new application's directory: cd name_of_your_app
    5. Right-click on your CodeAnywhere Connection, and select "info" from the context menu.
    6. At the bottom of the page that opens, you will see the web address for your rails application. (For example: http(s)://RailsW20-kurmasz.codeanyapp.com)
    7. Right-click on your CodeAnywhere Connection and select "Refresh from the context menu.
    8. Edit config/environments/development.rb to contain a line analogous to config.hosts << 'railsw20-kurmasz.codeanyapp.com' Notice that the string is all lower case.
    9. Be sure to save the file.
    10. Launch rails: rails s --binding=0.0.0.0
      • If you get a help/"usage" display, then you ran the rails command from the wrong directory.
    11. The information page for your container will contain a link to your web app. When you click it, you should see the default Rails landing page.

This screencast walks through the above steps: youtu.be/YG1_xks0lFw.

How to update Node: hosting.review/tutorial/how-to-update-node/


Updated Friday, 10 April 2020, 8:03 PM

W3c Validation