내 애플 리케이션에서 로직 captcha를 구현하려고합니다. DB에 질의 응답을 저장하기 위해 간단한 TextCaptcha를 스캐 폴딩했습니다.레일 3 - 확장 ActionController
현재 내가 초기화/text_captcha.rb이있다 "lib 디렉토리/text_captcha.rb"에서
require 'text_captcha'
ActionController::Base.send(:include, TextCaptcha)
이 : 댓글 컨트롤러 그래서
module TextCaptcha
def self.included(base)
base.send(:include, InstanceMethods)
end
module InstanceMethods
def require_text_captcha
@captcha = "hello!"
end
end
end
나는이 @에 액세스 할 필요 보기의 captcha
before_filter :require_text_captcha
나쁜 점은 내가 변경할 때마다 webrick을 다시 시작해야한다는 것입니다. 내가 잘못하고있는거야? initializer를 없애고 필요할 때 "text_captcha"를 요구할 수 있습니다. 또는 처음에 시도하려고 시도했지만 알아낼 수있는 "models/text_capctha.rb"에서이 작업을 수행 할 수있는 방법이 있습니다.
당신이 지금 게시 하시길 바랍니다. –
내 접근법의 또 다른 문제점은 TextCaptcha.find (: all)와 같은 것을 할 수 없다는 것입니다. 올바르게 기억하면 메서드 오류가 없습니다. –