天天看點

ruby 到 rails1. ruby和資料庫的連接配接2. ActiveRecord3. fastCGI和lighttpd

1. ruby和資料庫的連接配接

ruby的貢獻者實作了很多連接配接外圍資料庫的interface,大都基于C。即在DHH之前,這些庫已經存在。連接配接到oracle、通過ruby的接口有許多,目前OCI8占優。它們實作了類似jdbc的功能。

2. ActiveRecord

Rails and Active Record are both projects conceived by DavidHeinemeierHansson and improved upon by a number of Contributors.(http://wiki.rubyonrails.org/rails/pages/ActiveRecord )

ActiveRecord是ruby中一個獨立的ORM lib,DHH也将其作為rails中的model 部分。

寫道 The library for Ruby is named after Martin Fowler's "Active Record" design

pattern. In essence, it ties database tables to classes so that the data can be manipulated

intuitively without SQL. To be more specific, it "wraps a row in a database table or view,

encapsulates the database access, and adds domain logic on that data"

The ubiquity of both these models (RDBMS and OOP) and the "impedance mismatch" between

them has led many people to try to bridge this gap. The software bridge that accomplishes

this is called an Object-Relational Mapper (ORM).

3. fastCGI和lighttpd

Apache實作fcgi的插件有問題,是以不能使用來搭配rails(知道不能是fcgi的方式)。

lighttpd的配置備忘。

要用Apache隻能低于1.3版本,因為apache的fcgi對應插件在04年就停止開發,1.3之後的版本都有相容性問題。

server.error-handler-404 = "/dispatch.fcgi"

這句話使得可以把動态資源定向到ruby的fcgi程序。

############ BEGIN HIGHLIGHT ##################
fastcgi.server = ( ".fcgi" =>
    ( "localhost-8000" => ( "host" => "127.0.0.1", "port" => 8000 ) , 
    "localhost-8001" => ( "host" => "127.0.0.1", "port" => 8001 ) ,
    "localhost-8002" => ( "host" => "127.0.0.1", "port" => 8002 ) )
)
############ END HIGHLIGHT ##################
      

cgi是每次啟動一個程序來執行腳本,執行完畢傳回結果後消除程序。fcgi是把請求分發給某個事先跑起來的程序,執行完畢後程序進入後續隊列。

疑問是cgi這種運作方式怎麼會産生的,而且還存在了那麼多年。