# Rails Installation

Pre-Requisites

You need Rails 5, Ruby 2.3.1 installed on your system.

You will also require NodeJS for compiling ES6 based React files. To download NodeJS visit this installation page: https://nodejs.org/en/ and download Node v6.3.1 and above.


For Windows users only:

If you are on Windows, you need to setup your system to be able to compile Node native modules. There are two options available:

  • Option 1 (recommended): Install all the required tools and configurations using Microsoft's windows-build-tools for compiling Node modules. To do that just run: npm install --global --production windows-build-tools from an elevated PowerShell or CMD.exe (run as Administrator).

  • Option 2: Install tools and configuration manually:

    • Visual C++ Build Environment:

      • Option 1: Install Visual C++ Build Tools using the Default Install option.

      • Option 2: Install Visual Studio 2015 (or modify an existing installation) and select Common Tools for Visual C++ during setup. This also works with the free Community and Express for Desktop editions.

    • Install Python 2.7 (v3.x.x is not supported), and run npm config set python python2.7

    • Launch cmd, npm config set msvs_version 2015


Setup your project:

Once you have Node, Ruby, Rails setup, open a terminal/command prompt and change the current working directory to the rails directory in your downloaded Rubix folder like so (on Windows you would need to replace the backward slash "/" with the forward slash "\"):

$ cd rubix/rails

As you can see, the rails directory has two sub-directories: A rails seed named rails-seed and a simple Todo list example app named rails-example.

We will be re-creating the rails-example app, which, you can use as a reference for this tutorial. Please clone the rails-seed directory and rename the new copy to rails-todolist. (The installation steps for rails-example is the same as below so we won't be repeating it here)

$ cp -rf rails-seed rails-todolist

Change the working directory to rails-todolist and install all the project dependencies:

$ cd rails-todolist
$ npm install

You may get some deprecation warnings as well as peerDependency warnings in your terminal while/after the NPM installation. Please ignore those warnings.

Then run bundle install and setup Rails binaries:

$ bundle install
$ rake app:update:bin

Now, instead of launching rails s we will launch a Node webpack development server which in turn spawns a rails server as a child process. This step is only needed in development and not in production.

$ npm run dev -s

You should see an output similar to this:

[2] Waiting for public/js/server.js (max 120 seconds)
[1] http://localhost:8079/webpack-dev-server/
[1] webpack result is served from http://localhost:8079/assets/
[1] content is served from http://localhost:8079
[0] Hash: f73927b788612636a8ef
[0] Version: webpack 1.13.1
[0] Time: 23765ms
[0]               Asset     Size  Chunks             Chunk Names
[0] public/js/server.js  1.82 MB       0  [emitted]  main
[0]    [0] multi main 28 bytes {0} [built]
[0]     + 720 hidden modules
[2] Ready. public/js/server.js added
[2] => Booting Puma
[2] => Rails 5.0.0 application starting in development on http://localhost:3000
[2] => Run `rails server -h` for more startup options
[2] DEPRECATION WARNING: Sprockets method `register_engine` is deprecated.
[2] Please register a mime type using `register_mime_type` then
[2] use `register_compressor` or `register_transformer`.
[2] https://github.com/rails/sprockets/blob/master/guides/extending_sprockets.md#supporting-all-versions-of-sprockets-in-processors
[2]  (called from block in <class:Railtie> at /usr/local/lib/ruby/gems/2.2.0/gems/react-rails-1.8.0/lib/react/rails/railtie.rb:110)
[2] Puma starting in single mode...
[2] * Version 3.5.2 (ruby 2.2.3-p173), codename: Amateur Raccoon Rocketry
[2] * Min threads: 5, max threads: 5
[2] * Environment: development
[2] * Listening on tcp://localhost:3000
[2] Use Ctrl-C to stop

Ignore the deprecation warnings.

Your webserver has started on port 3000. Navigate to http://localhost:3000 in your browser. You should be greeted by a "Message from Server: Hello, World!" page.

With installation complete click "Next" to start creating our Todo list app.