Several days ago, I finished install Rails on my system. At that time, I didn’t have anything to show you about the easiness of Rails.
In this occasion I will show you how easy it is to create a simple web-based application. The application will just display “hello” and “goodbye”.
First, I create an application called “demo” :
$ rails demo
Next, I create a controller “Say” :
$ cd demo
$ ruby script/generate controller Say
Then I create two actions in say_controller.rb :
$ cd app/controllers
Here is my say_controller.rb file :
class SayController def hello
@time = Time.now
Next, I create two views for each action (hello.rhtml and goodbye.rhtml) :
$ cd app/views/say
Here is the content of hello.rhtml :
Hello from Rails!
It is now .
Time to say
Here is the content of goodbye.rhtml :
It was nice having you here.
Say “hello” %> again.
After that I start the server :
=> Booting WEBrick…
=> Rails application started on http://0.0.0.0:3000
=> Ctrl-C to shutdown server; call with –help for options
[2006-07-12 22:16:23] INFO WEBrick 1.3.1
[2006-07-12 22:16:23] INFO ruby 1.8.4 (2005-12-24) [i586-linux]
[2006-07-12 22:16:23] INFO WEBrick::HTTPServer#start: pid=5225 port=3000
Now it’s time to show some pretty pictures. :D