关于使用Rails在线文档

时间:2010-11-22 19:54:27

标签: ruby-on-rails

嘿伙计们 我是Rails的新手 我在默认的application_controller.rb中找到了这个代码,它由rails generator

生成
class ApplicationController < ActionController::Base
  protect_from_forgery
end

然后在我检查在线文档中的protect_from_forgery方法后,我发现它在ActionController :: RequestForgeryProtection模块而不是ActionController :: Base

可以告诉我为什么,以及如何检查我可以使用ApplicationController类的方法

谢谢

2 个答案:

答案 0 :(得分:1)

您可以使用模块将功能混合到您的课程中。 这是ruby继承的一个特性。

因此,如果它是您正在使用的模块,您可以require然后include将模块提供的功能混合到您的班级中。

有关mixins的更多信息:http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html

答案 1 :(得分:1)

这是因为ActionController :: Base包含ActionController :: RequestForgeryProtection

您可以在ActionController :: Base中看到所有模块包含:http://api.rubyonrails.org/classes/ActionController/Base.html