Ruby On Rails: Introduction

Here I ‘m going to extend my previous testapp. Also learn more about ruby on rails file structure. Ref: http://www.belajarrubyonrails.com/2012/12/membuat-aplikasi-rails-sederhana-say.html

Extend Controller.
Create a new controller ‘home_controller.rb’ in /app/controllers/ directory. Here is the content:

 

Extend View.
Create a new directory ‘home’ in /app/views/ directory. Then create a new file ‘index.html.erb’ in the new directory. Here is the content:

Then remove ‘index.html’ file in /public/directory (I DONT FIND IT!!!)

Routes.
Modify ‘routes.rb’ file in /config/ directory. Set the default route to our testapp.

Then start the rails server (rails s) and open it in http://localhost:3000/. It should show this text:

 

I want to show Date and Time on my browser. Modify ‘home_controller.rb’ like this:

Then modify ‘index.html.erb’ to show the date time:

OK. Start the server and open it on the browser. It should be something like this:show-datetime-testapp

 

Leave a Reply

Your email address will not be published. Required fields are marked *