Module: SimpleCaptcha::ModelHelpers::InstanceMethods
- Defined in:
- lib/simple_captcha/active_record.rb
Instance Method Summary collapse
- #is_captcha_valid? ⇒ Boolean
- #save_with_captcha ⇒ Object
- #simple_captcha_valid? ⇒ Boolean
- #update_attributes_with_captcha(*args) ⇒ Object
- #valid_with_captcha? ⇒ Boolean
Instance Method Details
#is_captcha_valid? ⇒ Boolean
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/simple_captcha/active_record.rb', line 62 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] || 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) errors.add(:captcha, ) return false end end |
#save_with_captcha ⇒ Object
83 84 85 |
# File 'lib/simple_captcha/active_record.rb', line 83 def save_with_captcha valid_with_captcha? && save(:validate => false) end |
#simple_captcha_valid? ⇒ Boolean
58 59 60 |
# File 'lib/simple_captcha/active_record.rb', line 58 def simple_captcha_valid? self.errors[:captcha].empty? end |
#update_attributes_with_captcha(*args) ⇒ Object
79 80 81 |
# File 'lib/simple_captcha/active_record.rb', line 79 def update_attributes_with_captcha *args valid_with_captcha? && update_attributes(*args) end |
#valid_with_captcha? ⇒ Boolean
54 55 56 |
# File 'lib/simple_captcha/active_record.rb', line 54 def valid_with_captcha? [valid?, is_captcha_valid?].all? end |