Module: SimpleCaptcha::ModelHelpers::SingletonMethods
- Defined in:
- lib/simple_captcha/active_record.rb
Overview
To implement model based simple captcha use this method in the model as…
class User < ActiveRecord::Base
apply_simple_captcha :message => "my customized message"
end
Customize the error message by using :message, the default message is “Captcha did not match”. As in the applications captcha is needed with a very few cases like signing up the new user, but not every time you need to authenticate the captcha with @user.save. So as to maintain simplicity here we have the explicit method to save the instace with captcha validation as…
-
to validate the instance
@user.valid_with_captcha? # whene captcha validation is required.
@user.valid? # when captcha validation is not required.
-
to save the instance
@user.save_with_captcha # whene captcha validation is required.
@user.save # when captcha validation is not required.
Instance Method Summary collapse
Instance Method Details
#apply_simple_captcha(options = {}) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/simple_captcha/active_record.rb', line 32 def apply_simple_captcha( = {}) = { :add_to_base => false }.merge() class_attribute :simple_captcha_options self. = unless self.is_a?(ClassMethods) include InstanceMethods extend ClassMethods attr_accessor :captcha, :captcha_key end end |