作者stayfool (fool)
看板Ruby
标题[问题] 语法问题请教
时间Fri Feb 15 23:50:12 2013
环境:
e.g. Ruby 1.8.7 + Rails 3.2.8
状况:
class ApplicationController < ActionController::Base
protect_from_forgery #问题点
end
protect_from_forgery 这个方法是在rails API 文件
http://api.rubyonrails.org/classes/ActionController/RequestForgeryProtection/ClassMethods.html#method-i-protect_from_forgery
ActionController::RequestForgeryProtection::ClassMethods
的里面才会有的方法,而ApplicationController 的父类别是ActionController::Base
,此类别中没有protect_from_forgery这个方法,为什麽可以在ApplicationController
直接使用此方法呢?
ActionController::Base 与ActionController::RequestForgeryProtection::ClassMethods
这两个modules间有什麽关系存在导致可以方法可以互相使用吗?
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 114.32.151.236
1F:→ aquarianboy:你可以试着到rails project的目录底下输入 rails c 02/17 04:51
2F:→ aquarianboy:进入console模式 02/17 04:52
3F:→ aquarianboy:然後输入 puts ActionController::Base.ancestors 02/17 04:52
4F:→ aquarianboy:会发现其实事情并不单纯 :) 02/17 04:52