
資料來源: Agile Web Development with Rails
Ruby on Rails 是讓開發,佈署與維護更簡單的框架。
應用程式被分解為三種元素: models,views,controllers(MVC)
- The model is responsible for maintaining the state of the application.A model is more than just data; it enforces all the business rules that apply to that data.
- The view is responsible for generating a user interface, normally based on data in the model.
- Controllers orchestrate the application. controllers receive events from the outside world, interact with the model,and display an approach view to the user.
那麼 ruby on rails 有甚麼特色呢?
- 在 Model 方面,採用了 Object-Relational Mapping(ORM),也就是將資料庫的表格對應到 class。可對應的包括table 的欄位,table 與 table 的關係與 table 的內容邏輯性。
例如:
Order.find(:all , :conditions => "name='dave'").each do |order|
puts order.amount
end - 在view 方面,動態頁面由 templates 產生,其包含了三個元素(原文 flavors)
- rhtml,最簡單也最容易。( 靜態頁面加上動態產生的元素)
- rjs,允許在 server 創建 JavaScript 片段並且在 broswer 執行
- controller 是應用的邏輯中心,並負責將外部的請求以轉到內部的 action,而這個過程僅以簡單的 URL 表達。
例如 http://127.0.0.1/say/hello
say -> controller
hello -> action
沒有留言:
張貼留言