{"id":1389,"date":"2017-01-09T15:13:40","date_gmt":"2017-01-09T15:13:40","guid":{"rendered":"http:\/\/myprojects.advchaweb.com\/?p=1389"},"modified":"2017-01-09T15:44:07","modified_gmt":"2017-01-09T15:44:07","slug":"ruby-on-rails-introduction","status":"publish","type":"post","link":"https:\/\/myprojects.advchaweb.com\/index.php\/2017\/01\/09\/ruby-on-rails-introduction\/","title":{"rendered":"Ruby On Rails: Introduction"},"content":{"rendered":"<p>Here I &#8216;m going to extend my previous <a href=\"http:\/\/myprojects.advchaweb.com\/index.php\/2017\/01\/09\/ruby-on-rails-installation-on-ubuntu-14-04\/\" target=\"_blank\">testapp<\/a>. Also learn more about ruby on rails file structure. Ref: <a href=\"http:\/\/www.belajarrubyonrails.com\/2012\/12\/membuat-aplikasi-rails-sederhana-say.html\">http:\/\/www.belajarrubyonrails.com\/2012\/12\/membuat-aplikasi-rails-sederhana-say.html<\/a><\/p>\n<p><span style=\"background-color: #008000;\">Extend Controller<\/span>.<br \/>\nCreate a new controller &#8216;home_controller.rb&#8217; in \/app\/controllers\/ directory. Here is the content:<\/p>\n<pre class=\"lang:default decode:true \">class HomeController &lt; ApplicationController\r\n    def index\r\n    end\r\nend<\/pre>\n<p>&nbsp;<\/p>\n<p><span style=\"background-color: #008000;\">Extend View<\/span>.<br \/>\nCreate a new directory &#8216;home&#8217; in \/app\/views\/ directory. Then create a new file &#8216;index.html.erb&#8217; in the new directory. Here is the content:<\/p>\n<pre class=\"lang:default decode:true \">Hello Ruby on Rails!!! Here I am!!!<\/pre>\n<p>Then remove &#8216;index.html&#8217; file in \/public\/directory (I DONT FIND IT!!!)<\/p>\n<p><span style=\"background-color: #008000;\">Routes<\/span>.<br \/>\nModify &#8216;routes.rb&#8217; file in \/config\/ directory. Set the default route to our testapp.<\/p>\n<pre class=\"lang:default decode:true \">Rails.application.routes.draw do\r\n  # For details on the DSL available within this file, see http:\/\/guides.rubyonrails.org\/routing.html\r\n#Testapp::Application.routes.draw.do --&gt; WHY NOT WORKING??? rails s SHOWED ERROR\r\n    root :to =&gt; 'home#index'\r\nend<\/pre>\n<p>Then start the rails server (rails s) and open it in http:\/\/localhost:3000\/. It should show this text:<\/p>\n<pre class=\"lang:default decode:true \">Hello Ruby on Rails!!! Here I am!!!<\/pre>\n<p>&nbsp;<\/p>\n<p>I want to show Date and Time on my browser. Modify &#8216;home_controller.rb&#8217; like this:<\/p>\n<pre class=\"lang:default decode:true \">class HomeController &lt; ApplicationController\r\n    def index\r\n        @time_now = Time.now\r\n    end\r\nend<\/pre>\n<p>Then modify &#8216;index.html.erb&#8217; to show the date time:<\/p>\n<pre class=\"lang:default decode:true \">&lt;h1&gt;Hello Ruby on Rails!!! Here I am!!!&lt;\/h1&gt;\r\n\r\n&lt;p&gt;Time now is &lt;%= @time_now %&gt;&lt;\/p&gt;<\/pre>\n<p>OK. Start the server and open it on the browser. It should be something like this:<a href=\"http:\/\/myprojects.advchaweb.com\/wp-content\/uploads\/2017\/01\/show-datetime-testapp.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1394\" src=\"http:\/\/myprojects.advchaweb.com\/wp-content\/uploads\/2017\/01\/show-datetime-testapp.png\" alt=\"show-datetime-testapp\" width=\"559\" height=\"145\" srcset=\"https:\/\/myprojects.advchaweb.com\/wp-content\/uploads\/2017\/01\/show-datetime-testapp.png 559w, https:\/\/myprojects.advchaweb.com\/wp-content\/uploads\/2017\/01\/show-datetime-testapp-300x78.png 300w\" sizes=\"auto, (max-width: 559px) 85vw, 559px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here I &#8216;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 &#8216;home_controller.rb&#8217; in \/app\/controllers\/ directory. Here is the content: class HomeController &lt; ApplicationController def index end end &nbsp; Extend View. Create a new directory &#8216;home&#8217; in \/app\/views\/ directory. Then create &hellip; <a href=\"https:\/\/myprojects.advchaweb.com\/index.php\/2017\/01\/09\/ruby-on-rails-introduction\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Ruby On Rails: Introduction&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[50,13],"tags":[],"class_list":["post-1389","post","type-post","status-publish","format-standard","hentry","category-ruby-on-rails","category-tutorial"],"_links":{"self":[{"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/posts\/1389","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/comments?post=1389"}],"version-history":[{"count":6,"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/posts\/1389\/revisions"}],"predecessor-version":[{"id":1396,"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/posts\/1389\/revisions\/1396"}],"wp:attachment":[{"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/media?parent=1389"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/categories?post=1389"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/tags?post=1389"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}