Module: SignedForm::ActionView::FormHelper

Defined in:
lib/signed_form/action_view/form_helper.rb

Instance Method Summary collapse

Instance Method Details

#form_for(record, options = {}, &block) ⇒ Object

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :sign_destination (Boolean)

    Only the URL given/created will be allowed to receive the form.

  • :digest (Boolean)

    Digest and verify the views have not been modified

  • :digest_grace_period (Integer)

    Time in seconds to allow old forms

  • :wrap_form (Symbol)

    Method of a form builder to wrap. Default is form_for



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/signed_form/action_view/form_helper.rb', line 9

def form_for(record, options = {}, &block)
  if options[:signed].nil? && !SignedForm.options[:signed] || !options[:signed].nil? && !options[:signed]
    return super
  end

  options = SignedForm.options.merge options
  options[:builder] ||= ::ActionView::Helpers::FormBuilder

  ancestors = options[:builder].ancestors

  if !ancestors.include?(::ActionView::Helpers::FormBuilder) && !ancestors.include?(SignedForm::FormBuilder)
    raise "Form signing not supported on builders that don't subclass ActionView::Helpers::FormBuilder or include SignedForm::FormBuilder"
  elsif !ancestors.include?(SignedForm::FormBuilder)
    options[:builder] = SignedForm::FormBuilder::BUILDERS[options[:builder]]
  end

  super record, options do |f|
    output = capture(f, &block)
    f.form_signature_tag + output
  end
end