2011年3月6日 星期日

create a new view and routes to view in Rails.

rails generate controller home index

vi config/routes.rb

add resources :timelines

rake routes (to view all routes in this app).

在 ubuntu 10.04 安裝 rails 3.0

http://www.web2linux.com/05/installing-rails-3-on-ubuntu-10-04-lucid-lynx/

URL教你安裝 ruby and rvm

http://ithelp.ithome.com.tw/question/10051215

如果你有 rvm, (如果還沒安裝, 趕快裝!)

我用它來升級 ruby 版本

$ rvm install ruby-1.9.2
Installing Ruby from source to: /home/ming/.rvm/rubies/ruby-1.9.2-p180, this may take a while depending on your cpu(s)...

ruby-1.9.2-p180 - #fetching
ruby-1.9.2-p180 - #extracted to /home/ming/.rvm/src/ruby-1.9.2-p180 (already extracted)
ruby-1.9.2-p180 - #configuring
ruby-1.9.2-p180 - #compiling
ruby-1.9.2-p180 - #installing
ruby-1.9.2-p180 - Updating #rubygems to the latest.
Removing old Rubygems files...
Installing rubygems dedicated to ruby-1.9.2-p180...
Installing rubygems for /home/ming/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
Installation of rubygems completed successfully.
ruby-1.9.2-p180 - Updating #rubygems to the latest.
Removing old Rubygems files...
Installing rubygems dedicated to ruby-1.9.2-p180...
Installing rubygems for /home/ming/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
ruby-1.9.2-p180 - Updating #rubygems to the latest.
Removing old Rubygems files...
Installing rubygems dedicated to ruby-1.9.2-p180...
Installing rubygems for /home/ming/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
Installation of rubygems completed successfully.
ruby-1.9.2-p180 - Updating #rubygems to the latest.
Removing old Rubygems files...
Installing rubygems dedicated to ruby-1.9.2-p180...
Installing rubygems for /home/ming/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
ming@ming-Presario-V3000-GM179PA-AB0:~$ rvm install ruby-1.9.2
Installing Ruby from source to: /home/ming/.rvm/rubies/ruby-1.9.2-p180, this may take a while depending on your cpu(s)...

ruby-1.9.2-p180 - #fetching
ruby-1.9.2-p180 - #extracted to /home/ming/.rvm/src/ruby-1.9.2-p180 (already extracted)
ruby-1.9.2-p180 - #configuring
ruby-1.9.2-p180 - #compiling
ruby-1.9.2-p180 - #installing
ruby-1.9.2-p180 - Updating #rubygems to the latest.
Removing old Rubygems files...
Installing rubygems dedicated to ruby-1.9.2-p180...
Installing rubygems for /home/ming/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
Installation of rubygems completed successfully.
ruby-1.9.2-p180 - Updating #rubygems to the latest.
Removing old Rubygems files...
Installing rubygems dedicated to ruby-1.9.2-p180...
Installing rubygems for /home/ming/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
ruby-1.9.2-p180 - Updating #rubygems to the latest.
Removing old Rubygems files...
Installing rubygems dedicated to ruby-1.9.2-p180...
Installing rubygems for /home/ming/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
Installation of rubygems completed successfully.
ruby-1.9.2-p180 - Updating #rubygems to the latest.
Removing old Rubygems files...
Installing rubygems dedicated to ruby-1.9.2-p180...
Installing rubygems for /home/ming/.rvm/rubies/ruby-1.9.2-p180/bin/ruby

$ rvm install ruby-1.9.2
Installing Ruby from source to: /home/ming/.rvm/rubies/ruby-1.9.2-p180, this may take a while depending on your cpu(s)...

ruby-1.9.2-p180 - #fetching
ruby-1.9.2-p180 - #extracted to /home/ming/.rvm/src/ruby-1.9.2-p180 (already extracted)
ruby-1.9.2-p180 - #configuring
ruby-1.9.2-p180 - #compiling
ruby-1.9.2-p180 - #installing
ruby-1.9.2-p180 - Updating #rubygems to the latest.
Removing old Rubygems files...
Installing rubygems dedicated to ruby-1.9.2-p180...
Installing rubygems for /home/ming/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
Installation of rubygems completed successfully.
ruby-1.9.2-p180 - Updating #rubygems to the latest.
Installation of rubygems completed successfully.
ruby-1.9.2-p180 - adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
ruby-1.9.2-p180 - #importing default gemsets (/home/ming/.rvm/gemsets/)

what is a symble in Ruby?

:north
:a
:aSymble

它就是一個不需要 value (有值), 但要代表一個與衆不同的 id.

demo:


$ irb
irb(main):001:0> :north
=> :north
irb(main):002:0> a = :north
=> :north
irb(main):003:0> b = :north
=> :north
irb(main):004:0> a == b
=> true
irb(main):005:0> :north = 1
SyntaxError: compile error
(irb):5: syntax error, unexpected '=', expecting $end
:north = 1
^
from (irb):5
from :0
irb(main):006:0> puts :north
north
=> nil
irb(main):007:0> puts :north.to_s
north
=> nil
irb(main):008:0> :north == :north
=> true
irb(main):009:0> a == :north
=> true
irb(main):010:0> a = :north
=> :north
irb(main):011:0> a == :north
=> true
irb(main):012:0>