Module: Formz::FauxMethod

Defined in:
lib/formz/fauxmethod.rb

Overview

Formz::FauxMethod

Fake out methods using the hidden field ‘_method’ when the HTTP method is not GET or POST. Defaults the method to POST.

Instance Method Summary collapse

Instance Method Details

#create_tag(name, contents, attrs, &block) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/formz/fauxmethod.rb', line 13

def create_tag name, contents, attrs, &block
  if name == :form
    attrs[:method] ||= :post
    unless valid_http_method? attrs[:method]
      method = Tagz.tag :input, :type => :hidden, :name => :_method, :value => attrs[:method]
      attrs[:method] = :post
      contents << method
    end
  end
  super
end

#valid_http_method?(method) ⇒ Boolean

Check if method is a valid form HTTP verb. (get, post).

Returns:

  • (Boolean)


28
29
30
# File 'lib/formz/fauxmethod.rb', line 28

def valid_http_method? method
  method.to_s.in? 'post', 'get'
end