Class: AwesomeForm::FormBuilder

Inherits:
ActionView::Helpers::FormBuilder
  • Object
show all
Includes:
Methods::Actions, Methods::Attributes, Methods::Inputs, Methods::Labels, Methods::Naming
Defined in:
lib/awesome_form/form_builder.rb

Instance Method Summary collapse

Methods included from Methods::Labels

#action_label, #input_label

Methods included from Methods::Naming

#association_name, #collection_name, #input_id, #input_name

Methods included from Methods::Rendering

#render_method

Methods included from Methods::Attributes

#discover_attributes

Constructor Details

#initializeFormBuilder

Returns a new instance of FormBuilder.



15
16
17
# File 'lib/awesome_form/form_builder.rb', line 15

def initialize(*)
  super
end

Instance Method Details

#filter_attributes_for(html, options) ⇒ Object



35
36
37
38
39
40
# File 'lib/awesome_form/form_builder.rb', line 35

def filter_attributes_for(html, options)
  options.select do |k|
    AwesomeForm.legal_attributes[html].include?(k) ||
    k.to_s =~ /^data($|-)/
  end
end

#lookup_views(paths) ⇒ Object



31
32
33
# File 'lib/awesome_form/form_builder.rb', line 31

def lookup_views(paths)
  paths.select { |p| view_exists? p }.first
end

#model_nameObject



42
43
44
# File 'lib/awesome_form/form_builder.rb', line 42

def model_name
  object.class.name.underscore
end

#render(render_options) ⇒ Object



19
20
21
# File 'lib/awesome_form/form_builder.rb', line 19

def render(render_options)
  @template.render(render_options)
end

#resource_nameObject



46
47
48
# File 'lib/awesome_form/form_builder.rb', line 46

def resource_name
  model_name.pluralize
end

#view_exists?(view) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
# File 'lib/awesome_form/form_builder.rb', line 23

def view_exists?(view)
  path_elements = view.split('/')
  view = "_#{path_elements.pop}".squeeze '_'
  prefix = path_elements.join('/')

  @template.lookup_context.exists? view, [prefix]
end