First steps with ActiveRuby

There are many great features available out of the box to help you get started developing with Ruby and Rails.

Bundled documentation

When learning any new language, the docs are a great place to start. We’ve bundled a wealth of Ruby and Rails documentation with the ActiveRuby distribution. You can launch it from the Windows Start menu. After it launches, you can browse installed gems and read individual gem documentation.

Verifying your installation

ActiveRuby gets you up and running with Ruby and Rails on Windows very quickly. After you install ActiveRuby, you can complete a few quick checks to verify that your development environment is configured correctly.

  1. Open PowerShell and verify the Ruby and Rails versions and the installed gems.

    • Verify that the default configured Ruby is ActiveRuby:

      > ruby --version
      ActiveRuby 2.3.4.2304
      
    • Check the Rails version

      > rails --version
      Rails 5.1.2
      
    • Check the Gem version

      > gem --version
      2.5.2
      
    • List the set of gems and versions installed by ActiveRuby

      > gem list
      ...
      

      You can access the documentation for any of the gems from the complete list of included gems.

Getting started with Ruby

The Ruby in 20 Minutes tutorial is a good place to start if you are new to Ruby.

Enter irb on the command line to start interactive Ruby and work through the tutorial.

Getting started with Rails

  1. Create a workspace for your Rails projects.

    > cd
    > mkdir workspace
    > cd workspace/
    
  2. Create a new Rails project:

    > rails _5.1.2_ new hello_activeruby
    

    NOTE: By default, Rails searches for the latest version of gems when you create a new rails application. You can prevent this, and rely on the gems installed with ActiveRuby, by adding the --skip-bundle switch.

    > rails _5.1.2_ new hello_activeruby --skip-bundle
    
  3. Open an new terminal tab, and run rails project and navigate to it in your web browser at http://localhost:3000:

    > rails server
    
  4. Add content to your Rails application - in this example a simple “Hello, ActiveRuby on Rails” message.

    1. Locate the app/controllers/application_controller.rb file in your Rails application directory and open it in your editor.

    2. Update the file with the following code and then save it.

      class ApplicationController < ActionController::Base
          protect_from_forgery with: :exception
      
          def hello
              render html: "Hello, ActiveRuby on Rails"
          end
      end
      
  5. Configure routing for the hello action.

    1. Locate the default routing file (config/routes.rb) in your Rails application directory and open it in your editor.
    2. Locate the line with Rails.application.routes.draw do.
    3. Update the route information with the following information and then save it.

      Rails.application.routes.draw do
          root 'application#hello'
      end  
      
  6. Reload the Rails application home page your web browser to view your changes.

For detailed information about getting started with Ruby on Rails, see the Ruby on Rails Tutorial.