Ruby on Rails - Ruby on Rails 5 Hello World Example - ruby on rails tutorial - rails guides - rails tutorial - ruby rails



How to write Hello World program in Ruby on Rails 5?

  • To create a simple Ruby on Rails 5 program displaying Hello World.
  • Ruby on Rails 5 program is different from Ruby on Rails 4 program.

Requirements

Text Editor:

  • You can utilize any text editor which is suitable for you. We are using Sublime Text editor which features many plugins.

Browser:

  • Default browser - Ubuntu,
  • Mozilla Firefox.
ruby on rails tutorial tags - ruby , rail , ruby on rails , rail forum , ruby on rails tutorial , ruby tutorial , rails guides , rails tutorial , learn ruby

Hello World Example

Step 1:

  • To Create a directory jtp in which all the code will be present and will navigate from the command line.
mkdir jtp  
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team

Step 2:

  • Change the directory to jtp
cd jtp
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team

Step 3:

  • Create a new application with the name helloWorld.
rails new helloWorld 
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team

Snapshot

 learn ruby on rails tutorial - ruby hello world example - ruby on rails example

learn ruby on rails tutorial - ruby hello world example - ruby on rails example

  • A helloWorld directory will be created in your system.
  • Inside this folder there will be many files and subfolders which is actually the Rails application.
ruby on rails tutorial tags - ruby , rail , ruby on rails , rail forum , ruby on rails tutorial , ruby tutorial , rails guides , rails tutorial , learn ruby

Step 4:

  • Move in to your above created application directory that is helloWorld.
cd helloWorld  
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team

Step 5:

  • Rails 5 has no longer a static index page in production. There will not be a root page in the production, so we need to create it. First we will create a controller called hello for our home page.
rails generate controller hello  
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
 learn ruby on rails tutorial - ruby hello world example - ruby on rails example

learn ruby on rails tutorial - ruby hello world example - ruby on rails example

Step 6:

  • Now we need to add an index page.
  • app/views/hello/index.html.erb
<h2>Hello World</h2>  
<p>
Welcome to wikitechy!!
</p> 
<p>   
  Today is 11 Aug, Friday.   
</p>  
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team

Step 7:

  • Now we need to route the Rails to this action. Edit the config/routes.rb file to set the index page to our new method.
  • Add the following line in the routes.rb file,
root 'hello#index'  
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team

Step 8:

  • Now you can verify the page by running your server.

rails server

 learn ruby on rails tutorial - ruby hello world example - ruby on rails example

learn ruby on rails tutorial - ruby hello world example - ruby on rails example

  • By default, Rails server listens to the port 3000. Although you can change it with the following command
rails server -p portNumber  
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team

Step 9:

  • Visit click here in your browser.
 learn ruby on rails tutorial - ruby hello world example- ruby on rails example

learn ruby on rails tutorial - ruby hello world example- ruby on rails example


This ruby on rails tutorial page provides you the following key areas such as ruby , rail , ruby on rails , rail forum , ruby on rails tutorial , ruby tutorial , rails guides , rails tutorial , learn ruby , rails form_for , ruby rails , ruby class , what is ruby on rails , rails installer , ruby online , learn ruby on rails , ruby on rails jobs , rails find_by , install rails , easyrail , rubyonrails , link_to rails , ruby on rails developer , learn ruby the hard way , railscasts , ruby on rails examples , ruby on rails vs php , rails 4 , rails activerecord , rails generate , ruby and rails , ruby on rails download , install ruby on rails , ruby net http , what is rails , ruby app , ruby vs ruby on rails , ruby on rails windows , rails for zombies , ruby on rails book , ruby on rails development , ruby on rails ide , ruby on rails tutorial pdf

Related Searches to Ruby on Rails 5 Hello World Example