只是我心中的一个想法。以下有什么区别
before_filter
class ApplicationController < ActionController::Base
before_filter :foo
def foo
@mode = Model.new
end
end
红宝石初始化
class ApplicationController < ActionController::Base
def initialize
foo
end
def foo
@mode = Model.new
end
end
- ruby 的初始化方法在 Rails 中是否按预期工作?
- 如果是,那么我们可以在适当的位置使用初始化过滤器必须应用于控制器中的所有操作吗?