1. Zero to “It Works!”
Just describe the basic gem, and how to use it
ActiveSupport: some utils like single to plural, time and date support
ActiveModel: thin wrapper around many different ActiveModel implementations to tell Rails how to use them
ActiveRecord: ORM
ActionPack: routing, request through controller, action, render to view
ActionMailer: email
- http code: 303 redirect
router的作法, 由rack的env來 找出controller和action
- autoloading
用to_underscore來找出所要呼叫的controller
再用const_missing和const_get來自動require
- Rendering Views
render: 先找出view的檔案 filename = File.join 'app', 'views', controller_name, "#{view_name}.html.erb"
def controller_name
klass = self.class
klass = klass.to_s.gsub /Controller$/, ''
Rulers.to_underscore klass
end
想從controller傳instance variable到view時需要用到instance_variables和instance_variable_get來倒到view
eruby.result locals.merge(:env => env).merge(view_assigns).merge(other_settings)
def view_assigns
hash = {}
variables = instance_variables
variables -= [:@env]
variables.each { |name| hash[name] = instance_variable_get(name) }
hash
end
5. Basic Models
like ActiveRecord
find, all, create, update …..
Exercise 2,3 沒做
6. Request, Response
using Rackʼs Request and Response objects
Exercise 沒做
7
8. Rack Middleware
use ‘use’ add layer by layer
沒有留言:
張貼留言