Class: Espresso::View::FormBuilder

Inherits:
Formtastic::SemanticFormBuilder
  • Object
show all
Defined in:
lib/espresso/view/form_builder.rb

Instance Method Summary collapse

Instance Method Details

#commit_button(*args) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/espresso/view/form_builder.rb', line 39

def commit_button(*args)
  options = args.extract_options!

  button_html = options.delete(:button_html) || {}
  button_html.merge!(:class => [button_html[:class], form_action].compact.join(' '))
  element_class = ['commit', options.delete(:class)].compact.join(' ')
  accesskey = (options.delete(:accesskey) || @@default_commit_button_accesskey) unless button_html.has_key?(:accesskey)
  button_html = button_html.merge(:accesskey => accesskey) if accesskey  
  template.(:li, self.submit(options.delete(:label), button_html), :class => element_class)
end

#inline_errors_for(method, options = nil) ⇒ Object

:nodoc:



14
15
16
17
18
19
20
21
22
# File 'lib/espresso/view/form_builder.rb', line 14

def inline_errors_for(method, options = nil) #:nodoc:
  if render_inline_errors?
    errors = Array(@object.errors[method.to_sym]) +
      Array(@object.errors[:"#{method}_id"])
    send(:"error_#{@@inline_errors}", [*errors]) if errors.present?
  else
    nil
  end
end

#submit(value = nil, options = {}) ⇒ Object



8
9
10
11
12
# File 'lib/espresso/view/form_builder.rb', line 8

def submit(value=nil, options={})
  value, options = nil, value if value.is_a?(Hash)
  value ||= submit_default_value
  @template.submit_tag(value, options.reverse_merge(:id => "#{object_name}_submit"))
end

#submit_default_valueObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/espresso/view/form_builder.rb', line 24

def submit_default_value
  model = if object.class.respond_to?(:model_name)
            object.class.human_name
          else
            @object_name.to_s.humanize
          end

  defaults = []
  defaults << :"helpers.submit.#{object_name}.#{form_action}"
  defaults << :"helpers.submit.#{form_action}"
  defaults << "#{form_action.to_s.humanize} #{model}"

  I18n.t(defaults.shift, :model => model, :default => defaults)
end