Thursday, October 2, 2008

Rails Hello World!

App\Controllers\say_controller.rb


class SayController < ApplicationController
    def hello
        @time = Time.now
    end

    def goodbye
    end

    def files
        @files = Dir.glob('*')
    end
end

app\views\say\hello.html.erb


<html>
<head>
<title>Hello, Rails!</title>
</head>
<body>
<h1>Hello from Rails!</h1>
<ul>
<li>Addition: <%= 1+2 %> </li>
<li>Concatenation: <%= "cow" + "boy" %> </li>
<li>Time in one hour: <%= 1.hour.from_now %> </li>
</ul>

<% 3.times do %>
Ho!<br />
<% end %>
Merry Christmas!
<br /><br />
<% 3.downto(1) do |count| -%>
<%= count %>...<br />
<% end -%>
Lift off!
<br /><br />
Email: <%= h("The <thekhuc@gmail.com>") %>

<p>
It is now <%= Time.now %>
</p>

<p>
It is now <%= @time %>
</p>

<p>
Time to say
<%= link_to "Goodbye!", :action => "goodbye" %>
</body>
</html>

http://localhost:3000/say/hello


Hello from Rails!



  • Addition: 3

  • Concatenation: cowboy

  • Time in one hour: 2008-10-03 06:23:33 UTC


Ho!
Ho!
Ho!
Merry Christmas!

3...
2...
1...
Lift off!

Email: The <thekhuc@gmail.com>

It is now Fri Oct 03 01:23:33 -0400 2008

It is now Fri Oct 03 01:23:33 -0400 2008

Time to say Goodbye!

app\views\say\goodbye.html.erb


<html>
<head>
<title>See You Later!</title>
</head>
<body>
<h1>Goodbye!</h1>
<p>
It was nice having you here.
</p>

<p>
Time to say
<%= link_to "Hello!", :action => "hello" %>
</body>
</html>

http://localhost:3000/say/goodbye


Goodbye!


It was nice having you here.

Time to say Hello!

app\views\say\files.html.erb


<html>
<head>
<title>Files</title>
</head>
<body>
<ul>
<% for file in @files %>
<li>file name is <%= file %></li>
<% end %>
</ul>
</body>
</html>

http://localhost:3000/say/files



  • file name is app

  • file name is config

  • file name is db

  • file name is doc

  • file name is lib

  • file name is log

  • file name is public

  • file name is Rakefile

  • file name is README

  • file name is script

  • file name is test

  • file name is tmp

  • file name is vendor