Ruby on rails 3 Rails 3-扩展ActionController

Ruby on rails 3 Rails 3-扩展ActionController,ruby-on-rails-3,extend,actioncontroller,Ruby On Rails 3,Extend,Actioncontroller,我正在尝试在我的应用程序中实现逻辑验证码。我已经构建了简单的文本验证码,将问题和答案存储在数据库中 目前,我在initializers/text_captcha.rb中有此功能 require 'text_captcha' ActionController::Base.send(:include, TextCaptcha) 在“lib/text_captcha.rb”中: 所以在comments controller中,我可以访问视图中的@captcha before_filter :requ

我正在尝试在我的应用程序中实现逻辑验证码。我已经构建了简单的文本验证码,将问题和答案存储在数据库中

目前,我在initializers/text_captcha.rb中有此功能

require 'text_captcha'
ActionController::Base.send(:include, TextCaptcha)
在“lib/text_captcha.rb”中:

所以在comments controller中,我可以访问视图中的@captcha

before_filter :require_text_captcha

糟糕的是,每次我进行更改时都必须重新启动webrick,所以我认为我这样做是错误的?我可以去掉初始值设定项,只需要在需要的地方使用“文本验证码”。。。或者在“models/text\u capctha.rb”中有没有一种方法可以做到这一点,我一开始就想这么做,但我能想出来。

如果Rails重新加载模型时,TextCaptcha被吹走了,那么修复方法是使用
来准备它,而不是使用初始值设定项来加载它。有关更多信息,请参阅以下参考资料:

官方文件:
短博客帖子:

如果Rails重新加载模型时TextCaptcha被吹走,那么修复方法是使用
来准备
而不是使用初始值设定项来加载它。有关更多信息,请参阅以下参考资料:

官方文件:
短博文:

既然Rails应用程序中的
ApplicationController
是从
ActionController::Base
扩展而来的,那么您能做到:

require 'text_captcha'
class ApplicationController < ActionController::Base
  include TextCaptcha
end
需要“文本验证码”
类ApplicationController

app/controllers/application\u controller.rb

中,由于Rails应用程序中的
ApplicationController
是从
ActionController::Base
扩展而来的,您能做到:

require 'text_captcha'
class ApplicationController < ActionController::Base
  include TextCaptcha
end
需要“文本验证码”
类ApplicationController

app/controllers/application\u controller.rb

中,我的方法的另一个问题是我无法执行类似于TextCaptcha的操作。查找(:all)-如果我记得正确,则没有方法错误。我的方法的另一个问题是我无法执行类似于TextCaptcha.find(:all)的操作-如果我没记错的话,没有方法错误。