Thursday, July 13, 2006

Saying Hello and Goodbye in Rails

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
create
create app/controllers
create app/helpers
create app/models
create app/views/layouts
...
create log/test.log

Next, I create a controller "Say" :
$ cd demo
$ ruby script/generate controller Say
exists app/controllers/
exists app/helpers/
create app/views/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
end
def goodbye
end
end


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, Rails!


Hello from Rails!



It is now <%= @time %>.



Time to say

<%= link_to "Goodbye!", :action => "goodbye" %>





Here is the content of goodbye.rhtml :

See You Later!



Goodbye!



It was nice having you here.



Say <%= link_to "Hello", :action => "hello" %> again.





After that I start the server :

$ pwd
demo

$ script/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





Installing Ruby on Rails

During my adventure to install Ruby on Rails, I didn't find a detailed guide explaining the process, what component should be install first, etc.

So here is my note regarding Ruby on Rails installation using gem. Please note that I install the components using gem local installation.

Install the following components first using gem :

# gem install activesupport-1.3.1.gem
Attempting local installation of 'activesupport-1.3.1.gem'
Successfully installed activesupport, version 1.3.1

Installing RDoc documentation for activesupport-1.3.1...


# gem install actionpack-1.12.3.gem
Attempting local installation of 'actionpack-1.12.3.gem'
Successfully installed actionpack, version 1.12.3
Installing RDoc documentation for actionpack-1.12.3...

# gem install actionmailer-1.2.3.gem
Attempting local installation of 'actionmailer-1.2.3.gem'
Successfully installed actionmailer, version 1.2.3
Installing RDoc documentation for actionmailer-1.2.3...

# gem install activerecord-1.14.3.gem
Attempting local installation of 'activerecord-1.14.3.gem'
Successfully installed activerecord, version 1.14.3
Installing RDoc documentation for activerecord-1.14.3...

# gem install rake-0.7.1.gem
Attempting local installation of 'rake-0.7.1.gem'
Successfully installed rake, version 0.7.1
Installing RDoc documentation for rake-0.7.1...

# gem install actionwebservice-1.1.4.gem
Attempting local installation of 'actionwebservice-1.1.4.gem'
Successfully installed actionwebservice, version 1.1.4
Installing RDoc documentation for actionwebservice-1.1.4...


Then install rails :

# gem install rails-1.1.4.gem
Attempting local installation of 'rails-1.1.4.gem'
Successfully installed rails, version 1.1.4


After that you can check whether rails has been installed using the following command :

$ rails --help
Usage: /usr/bin/rails /path/to/your/app [options]

...

View CHM Files in OpenSUSE 10.1

To be able to view chm files in OpenSUSE 10.1 you need to install the following software packages :

chmlib-0.37.4-1.i586.rpm
compat-expat1-1.95.8-6.i586.rpm

expat-2.0.0-13.i586.rpm

libmspack-0.0.20040308alpha-16.i586.rpm

wxGTK-2.6.1.0-4.i586.rpm

xchm-1.2-1.i586.rpm


You can find those packages in http://rpm.pbone.net


After success download those files, just install them :


# rpm -Uvh *.rpm


Enjoy