Ruby on Rails
Ruby on Rails, 也稱 RoR 或簡稱 Rails, 是一個使用Ruby語言寫的開源網絡應用 框架,它是嚴格按照Model-View-Controller (MVC) 結構開發的。它努力使自身保持簡單,來使實際的應用開發時的代碼更少,使用最少的配置。
Rails的設計原則包括「不要重複自己」(Don't Repeat Yourself)和「約定優於配置」(Convention Over Configuration)
歷史
Ruby on Rails 是從一個項目管理工具Basecamp中抽出來的,由David Heinemeier Hansson製做。它首次公開發布是在2004年6月。
Rails的 MVC 結構
Ruby on Rails的模型-視圖-控制器架構由以下各部分組成:
模型Model
在面向對象、數據庫驅動的MVC Web應用中,模型In object-oriented, database-driven MVC web applications, Model consists of the classes representing RDBMS tables.
在RoR中,模型類是通過Active Record模式進行處理的。一般來說,程式設計師要做的是繼承ActiveRecord
類,同時程序會自動計算出要使用哪個RDBMS表,這個表有哪些列。表與表之間的關係通過簡單的命令來指明。
視圖
在 MVC 中, 視圖View 是顯示的邏輯,也就是數據如何從控制器類中顯示出來的。在Web應用中,is the display logic, or how the data from the Controller classes is displayed. In web applications, this frequently consists of a minimal amount of code, interspersed in HTML.
Views are done as a fragment of HTML (.rhtml files) with Embedded Ruby interspersed or programmatically used in pure Ruby through Builder. The actual code is part of Rails' Action Pack, but programmers rarely need to touch it outside of Embedded Ruby.
For each method in the controller that needs to display user output, a small HTML code fragment needs to be written. The page layout is described separately from the controller action that displays layouts, and the fragments can also call other fragments.
控制器
在MVC中,控制器類用來處理應用程式的邏輯,它操作模型中的數據並通過視圖把數據顯示出來。在Web的MVC應用中,控制器方法是用戶通過Web瀏覽器來啟動的。
控制器 的實現是通過Rails的 Action Pack來進行處理,Action Pack有一個類,ApplicationController
。Rails 應用僅僅只要繼承ApplicationController
並把必須的行為以方法的形式寫出來,然後就可以通過Web訪問了。
Rails 也提供了預設狀態下的(out-of-the-box)腳手架,他可以快速構造大多數的必需邏輯和視圖來完成一般的操作,例如 CRUD。
其它模塊
In addition to this, Rails also offers some other modules, like Action Mailer for sending email and Action Web Service for SOAP and XML-RPC support.
Rails中的AJAX
一個獨立的技術稱為 AJAX,可以讓which allows for using Javascript and XML to process queries by a 瀏覽器 to a Web伺服器 as 後台處理 without 載入額外的網頁, has been combined with this technology to produce a system referred to as "Ajax on Rails". Rails 提供一些助手工具來更方便地實現AJAX應用。
Web伺服器支持
For development and testing, the lightweight WEBrick web server included with Ruby is often used as the application server. For production use, Apache or Lighttpd with FastCGI is recommended, but any web server with CGI or FastCGI support will work. On Apache, mod_ruby can help with performance considerably.
數據庫支持
Since the Rails architecture strongly favors database use, an RDBMS system is recommended for data storage, but Rails also supports the SQLite library if running an RDBMS server is not possible. Multiple RDBMS systems are supported, including MySQL, PostgreSQL, SQLite, DB2, Oracle and SQL Server.
這是一篇與電腦相關的小作品。您可以透過編輯或修訂擴充其內容。 |
外部連結
參考站點
- Ruby On Rails項目首頁
- Onlamp.com的Ajax on Rails
- Fast-track your Web apps with Ruby on Rails (David Mertz article at IBM developerWorks)
熱門的支持Ruby on Rails的空間服務
模板參量錯誤!(代碼36)
|