Skip to main content

Ruby on Rails

by v4.2.7.1 | Debian 9

Web framework to speed up development for modern web applications.

Discover a framework that’s optimized for programmer happiness. Ruby on Rails has become the foundation for developing web applications. The framework is the base for hundreds of thousands of applications including big names like GitHub, Hulu, and Shopify. As an open source project that’s been around since 2003, it is both well-established and has new improvements released through community contributions.

The Rails software comes with pre-programmed with assumptions about best practices to help speed up application development. Set up core infrastructure by launching Rails with Linode’s Ruby on Rails One-Click App.

Ruby on Rails Options

FIELDDESCRIPTION
Rails Application nameThe name for your rails application. Required.

Getting Started After Deployment

Access Ruby on Rails

  1. SSH into your Linode and create a limited user account.
  2. Log out and log back in as your limited user account.
  3. Update your server:
    sudo apt-get update && apt-get upgrade
  4. Ruby comes with some pre-made scripts to get you started. One of these is a blog. To begin with the blog example, use the following command:
    rails new blog
    This creates a new Rails application called Blog in the blog directory.
  5. Move into the blog directory:
    cd blog
  6. Start the built in server with the following command, replacing the IP address with your Linode’s IP address:
    rails server --binding=198.51.100.0

    Warning: Running `gem pristine --all` to regenerate your installed gemspecs (and deleting then reinstalling your bundle if you use bundle --path) will improve the startup performance of Spring. => Booting WEBrick => Rails 4.2.7.1 application starting in development on http://198.51.100.0:3000 => Run `rails server -h` for more startup options => Ctrl-C to shutdown server [2020-03-11 14:17:16] INFO WEBrick 1.3.1 [2020-03-11 14:17:16] INFO ruby 2.3.3 (2016-11-21) [x86_64-linux-gnu] [2020-03-11 14:17:16] INFO WEBrick::HTTPServer#start: pid=3089 port=3000
  7. You can visit your application by visiting the address in the browser.
Ruby on Rails Application Reference Image

8. Exit the server process with Ctrl+C

Create a Controller and View

A controller will receive requests which are then routed and served by various actions. A view displays information.

  1. Create a controller called Welcome and an action called index:

    rails generate controller Welcome index create app/controllers/welcome_controller.rb route get 'welcome/index' invoke erb create app/views/welcome create app/views/welcome/index.html.erb invoke test_unit create test/controllers/welcome_controller_test.rb invoke helper create app/helpers/welcome_helper.rb invoke test_unit invoke assets invoke coffee create app/assets/javascripts/welcome.coffee invoke scss create app/assets/stylesheets/welcome.scss
  2. With the text editor of your choice, edit the file app/views/welcome/index.html.erb and replace the contents with the following:

    app/views/welcome/index.html.erb

    1 <h1>Hello, World! This is Ruby on Rails!</h1>
  3. Tell Rails where to find the document root. Edit the file config/routes.rb, find and uncomment the line root as shown:

    config/routes

    Rails.application.routes.draw do
    get 'welcome/index'
    ...
    root 'welcome#index'
    ...
    end
  4. Start the server again:
    rails server --binding=198.51.100.0
    You should see your new welcome page in the web browser.

For more information on setting up a more substantial application, refer to the Ruby on Rails Getting Started Guide.

The Ruby on Rails One-Click App was built by Linode. For support regarding app deployment, contact Linode Support via the information listed in the sidebar. For support regarding the tool or software itself, visit the Ruby on Rails Stack Overflow.