Ruby: Crafting your first "hello world" application with Ruby on Rails

This documentation is part of the Getting started guide. You can view the complete guide here: Getting started with Ruby on Rails.

👋 Welcome to the Stackhero documentation!

Stackhero offers a ready-to-use Ruby cloud solution that provides a host of benefits, including:

  • Deploy your application in seconds with a simple git push.
  • Use your own domain name and benefit from the automatic configuration of HTTPS certificates for enhanced security.
  • Enjoy peace of mind with automatic backups, one-click updates, and straightforward, transparent, and predictable pricing.
  • Get optimal performance and robust security thanks to a private and dedicated VM.

Save time and simplify your life: it only takes 5 minutes to try Stackhero's Ruby cloud hosting solution!

Let's walk through the process of creating a simple "Hello World" application using Ruby on Rails.

  1. First, set up a new route for your application. Open the config/routes.rb file and define a root route that points to the hello#index action:

    Rails.application.routes.draw do
      root "hello#index"
    end
    
  2. Next, generate the Hello controller to manage the logic for this route. Run the following command in your terminal:

    bin/rails generate controller Hello index --skip-routes
    

    With this configuration, any request made to the URL path / will be handled by the HelloController.

  3. To display the "Hello World" message, create a view. Open the file at app/views/hello/index.html.erb and replace any existing content with the following code:

    <h1>Hello World!</h1>
    
  4. Finally, start the Rails server by running the command below in your terminal. Then, connect to your development URL (for example, http://<XXXXXX>.stackhero-network.com:3000) to view your application:

    bin/rails server -b 0.0.0.0
    

    First "Hello World" page in Ruby on RailsFirst "Hello World" page in Ruby on Rails

Congratulations. You have just created your first Ruby on Rails application!