Module: ProtectedForm::Helpers

Defined in:
lib/protected_form/helpers.rb

Instance Method Summary collapse

Instance Method Details

#protected_form_for(*attrs, &block) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/protected_form/helpers.rb', line 3

def protected_form_for *attrs, &block
  options = attrs.extract_options!

  id = 'pf_' + SecureRandom.hex(10)

  out = (:div, :id => id + '_form', :style => 'display:none;') do
    form_for(*attrs, options.dup, &(Proc.new {}))
  end

  form_content = fields_for(*attrs, options.dup, &block)

  out << (:div, form_content, :class => options[:html][:class] + ' js-protected-form', :id => id)
  out.html_safe
end