Module: Gotcha::FormHelpers

Defined in:
lib/gotcha/form_helpers.rb

Instance Method Summary collapse

Instance Method Details

#gotcha(options = {}) ⇒ Object

Propose a gotcha to the user - question and answer hash



6
7
8
9
10
11
12
13
14
15
# File 'lib/gotcha/form_helpers.rb', line 6

def gotcha(options = {})
  options[:label_options] ||= {}
  options[:text_field_options] ||= {}
  if gotcha = Gotcha.random
    field = "gotcha_response[#{gotcha.class.name.to_s}-#{Digest::MD5.hexdigest(gotcha.class.down_transform(gotcha.answer))}]"
    (label_tag field, gotcha.question, options[:label_options]) + "\n" + (text_field_tag field, nil, options[:text_field_options])
  else
    raise "No Gotchas Installed"
  end
end

#gotcha_errorObject

Return the gotcha error if its needed



18
19
20
# File 'lib/gotcha/form_helpers.rb', line 18

def gotcha_error
  t(:gotcha_validation_failed, :default => 'Failed to validate the Gotcha.') if @_gotcha_validated === false
end