Create a Demo Project

Before proceeding to the steps, make sure Ruby on Rails is installed on the system.

Step 1: Open the rails terminal, if you’re using Windows the terminal name will be ‘Ubuntu(WSL)’. Now run the following command. It will create a default project named ‘myapp’ in the current directory.

rails new myapp

;:rails new myapp

Step 2: Use this command to get into your project directory.

cd myapp

cd myapp

Step 3: Execute the below command in the terminal. It will create a controller file (home_controller.rb) in ‘app/controllers’ and corresponding view file (index.html.erb) which is our webpage in ‘app/views/home’. It will also create a route in ‘app/config/routes.rb’ which is needed for every webpage.

rails generate controller home index

rails generate controller home index

Step 4: Initially, when running the server, it gives the default welcome page as output. To display our home page, make changes in the ‘app/config/routes.rb’ file. Adding the following line in the file will set our home page as root.

root ‘home#index’

Set the home as root

Step 5: Run the server using the command below and view the output at ‘http://localhost:3000/’. You can also view the default web page if you don’t make any change in ‘routes.rb’.

rails server

rails server

Output:

Open the browser and paste the link ‘http://localhost:3000/’.

index.html.erb output

How to Create Button in Ruby on Rails?

Ruby on Rails, commonly known as Rails, is a popular web application framework written in the Ruby programming language. It follows the Model-View-Controller (MVC) architectural pattern, which separates the application’s data, logic, and user interface components. Rails emphasizes convention over configuration, which means it provides sensible defaults for getting started quickly without having to configure every aspect of the application.

Similar Reads

Create a Demo Project

Before proceeding to the steps, make sure Ruby on Rails is installed on the system....

Creating Buttons in Ruby on Rails

Method 1: Using HTML...

Contact Us