Module: MustacheForm::FormHelper

Defined in:
lib/mustache_form/form_helper.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



46
47
48
49
50
51
# File 'lib/mustache_form/form_helper.rb', line 46

def self.included(base)
  base.class_eval do
    alias_method :custom_form_tag, :mustache_form_tag
    alias_method :custom_form_for, :mustache_form_for
  end
end

Instance Method Details

#mustache_form_for(object, url_for_options: {}, html_options: {}, use_rails_form_helper: false) ⇒ Object

The form_for version in the basic form wraps the rails form_for helper and then yields to the method that handles the form inputs. It also handles the the optional use of the simple_form form helper. Since the method signature is identical it just needs to call the correct method name

-form_for(record, options = {}, &block) -simple_form_for(record, options = {}, &block)



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/mustache_form/form_helper.rb', line 32

def mustache_form_for(object, url_for_options: {}, html_options: {}, use_rails_form_helper: false)
  MustacheForm.simple_form_enabled == true ? formable = :simple_form_for : formable = :form_for
  formable = :form_for if use_rails_form_helper
  lambda do |text|
    options = {
      url: url_for_options, html: html_options
    }
    send(formable, object, options) do |f|
      obj = FormedMustache.new(yield(f))
      Mustache.render(text, obj).html_safe
    end
  end
end

#mustache_form_tag(url_for_options: {}, html_options: {}) ⇒ Object

The basic form_tag just wraps the rails form_tag helper and then yields to the view method that handles the form inputs

-form_tag(url_for_options = {}, options = {}, &block)



14
15
16
17
18
19
20
21
22
# File 'lib/mustache_form/form_helper.rb', line 14

def mustache_form_tag(url_for_options: {}, html_options: {})
  formable = :form_tag
  lambda do |text|
    send(formable, url_for_options, html_options) do |f|
      obj = FormedMustache.new(yield(f))
      Mustache.render(text, obj).html_safe
    end
  end
end