由於 Rails 2 已經推出了一段日子,我也來寫寫 Rails 2 要注意的地方。
Rails 2.0 is RESTful by default
我也來講講人稱 Sexy migration 的 ActiveRecord Migration,在 Rails 2.0 之前,migration 是長成這樣子的︰
1
2
3
4
5
6
7
8
9
10
11
12
13
| # db/migrate/001_create_customers.rb
class CreateCustomers < ActiveRecord::Migration
def self.up
create_table :posts do |t|
t.column :first_name, :string
t.column :last_name, :string
end
end
def self.down
drop_table :customers
end
end |
到了 Rails 2.0,migration 就變成這樣子︰
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| # db/migrate/001_create_customers.rb
class CreateCustomers < ActiveRecord::Migration
def self.up
create_table :posts do |t|
t.string :first_name
t.string :last_name
t.timestamps
end
end
def self.down
drop_table :customers
end
end |
除此之外,還新增了一個 rake task︰rake db:rollback,在以前,要 rollback 就只有用 rake db:migrate VERSION=xx 來做,新的 rake task 比較好用,不需要再去理會 version。
Rails 2.0.2 is out, this version fixed the rake rails:freeze:gem problem with RubyGens 0.9.5, this version is a drop-in replacement for Rails 2.0. From the release announcement.
Rails 2.0.2 contains a bunch of smaller fixes to various bugs, no show-stopping action, just further polish. But it also contains a few new defaults. The major change is mysql is no longer the default database. SQLite3 is the new default database, SQLite3 is shipped with Leopard. Use
$ rails -d mysql dummy_app
to set the default database to mysql.
Rails 2.0.1 已經正式推出了,而我也把我的 development machine update 到 2.0.1,但假如現在要 create 一個新的 Rails project,但又要用回 Rails 的舊版本如 1.2.6,應該怎麼辦呢?
做法很簡單,只要 create 新的 project 時指定版本即可
$ rails _1.2.6_ dummy_app
Update 10/12/2007 : It’s fixed in edge changeset 8336, it make rails:freeze:gems work with RubyGems 0.9.5. You can update to edge or follow the change set to update your frameworks.rake
When I try to create my own Rails 2.0 API documentation for reference. I encounter the cannot freeze gems problem. After a little googling, I’ve found the temporary fix. Until there is a solution I’ll stick with this fix.
1. create a dummy_app
rails dummy_app
2. edit /Library/Ruby/Gems/1.8/gems/rails-2.0.1/lib/tasks/framework.rake, add the following below line 6
[original]
line 6: require ‘rubygems’
[Fix]
line 6: require ‘rubygems’
line 7: require ‘rubygems/gem_runner’
3. delete the empty directory under vendor directory
4. rake rails:freeze:gems
5. echo >vendor/rails/activesupport/README
6. rake doc:rails
7. There is no step 7.
經過差不多一年的 Development effort,Rails 2.0 終於正式推出,Rails 2.0比上一版本 Rails 1.2改善了很多,例如 RESTful 的語法,Action Pack: Multiple View,Active Record 速度上的改進,更簡易的 Active Record: Migration,ActionController::HttpAuthentication 等。
詳情可以到 Rails 的 blog 看看。相信很多的 Rails 書也要跟著改版了,我想 AWDR 也很快會出第三版。
Rails Updated to 1.2.6, 1.2.6 is the stable version.
Rails 2.0 RC2 released, if there is no major issue in this version, Rails 2.0 will be released in a week or two.
Prototype 及 Script.aculo.us 剛剛推出了新的版本不夠兩日,就推出了 Rails 2.0 Release Candidate 1由 GemRails 升級到 EdgeRails,只要在你的 Rails Application Directory 打入
$ rake rails:freeze:edge TAG=rel_2-0-0_RC1
Rails 2.0 RC1 已包括了最新的 Prototype 及 Script.aculo.us。我想年底前應該就可以推出 Rails 2.0 的正式版本。
看到 Rails , Active Record 及 Active Support 等的版本是 1.99.0 就表示已經成功upgrade 到 EdgeRails(Rails 2.0 RC1) 囉﹗
Prototype 及 Script.aculo.us 剛剛推出了新的版本,分別是Prototype 1.6 及 Script.aculo.us 1.8,我想到 Ruby on Rails 推出 2.0 版本時應該會把 Prototype 及 Script.aculo.us 升級到這兩個版本。
剛剛升級到 Mac OS X 10.5 Leopard
升級到 Mac OS X 10.5 Leopard 的成本︰
| Mac OS X 10.5 Leopard |
HKD |
1,000.00 |
| iLife 08 |
HKD |
590.00 |
| 總數 |
HKD |
1,590.00 |

Leopard 預設已經安裝了 Ruby,Rails 等,但最近 Rails 推出了 1.2.4 及 1.2.5 兩個 bugfix 版本,所以要人手 update Rails。
$ gem update rails

今天終於收到了Lynda.com的Ruby On Rails Essential Training的CD了。包括有兩隻CD-Roms,總共有10.75小時的training video。

引述 XDite 的評語:這部影片講解得太好了。從 RoR 的設計理念、架構開始講,接著帶你從 model、controller、view,對 database 的 migrate 一步一步來,最後目的是實做一個商店。雖然每本書最前面都會一兩章講基礎架構,但都只是草草帶過。這部影片裡,光帶領新手理解 C / R / U / D 的 controller 到底必須怎麼撰寫運作,我就覺得非常值得稱許。它在令新手往往迷惘的地方講解的非常清楚與透徹。所以我推薦它應該成為新手的入門磚。
希望看完後能夠對 RoR 有更深入了解,寫 RoR 起來能夠得心應手,當然 AWDR 也是新手入門的不可缺少的一本書。