Module: SimpleCaptcha::ModelHelpers::InstanceMethods

Defined in:
lib/simple_captcha/active_record.rb

Instance Method Summary collapse

Instance Method Details

#is_captcha_valid?Boolean

Returns:

  • (Boolean)


56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/simple_captcha/active_record.rb', line 56

def is_captcha_valid?
  return true if Rails.env.test?

  if captcha && captcha.upcase.delete(" ") == SimpleCaptcha::Utils::simple_captcha_value(captcha_key)
    SimpleCaptcha::Utils::simple_captcha_passed!(captcha_key)
    return true
  else
    message = simple_captcha_options[:message] || I18n.t(self.class.model_name.downcase, :scope => [:simple_captcha, :message], :default => :default)
    simple_captcha_options[:add_to_base] ? errors.add(:base, message) : errors.add(:captcha, message)
    return false
  end
end

#save_with_captchaObject



69
70
71
# File 'lib/simple_captcha/active_record.rb', line 69

def save_with_captcha
  valid_with_captcha? && save(:validate => false)
end

#valid_with_captcha?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/simple_captcha/active_record.rb', line 52

def valid_with_captcha?
  [valid?, is_captcha_valid?].all?
end