DEV Community

Sagar Kattel
Sagar Kattel

Posted on

Create Hello World application in Ruby On Rails

Hello Folks,

Today we are going to learn how to create simple hello world application in ruby on rails. So hold your horses as i *embark * on you to your journey.

As you create the ruby on rails application with the command like


rails new project1
Enter fullscreen mode Exit fullscreen mode

This will create a simple ruby on rails application and now you need to enter inside it and just type

rails s 

Enter fullscreen mode Exit fullscreen mode

to start the server

Now what you need to do to display the "Hello World" application running is to go to the routes.rb file

And there specify what you want your routes folder to redirect it to:

root "controller_name#action"

root "pages#home"
Enter fullscreen mode Exit fullscreen mode

And now you need to create controller and for that you can simply write

rails generate controller pages

Enter fullscreen mode Exit fullscreen mode

This command will generate pages_controller.rb and will also generate pages folder inside views folder

And how inside the pages_controller.rb write these code

def home
end
Enter fullscreen mode Exit fullscreen mode

This command will invoke the controller to check the pages/home.html.erb file and display whatever is present there

And inside the pages folder create home.html.erb file and just type

Hello World! 

Enter fullscreen mode Exit fullscreen mode

And now you have successfully generated the Hello World Application. Sayonara <3

Top comments (0)