Class: ActionView::Helpers::AttributeBuilders::Button

Inherits:
Object
  • Object
show all
Includes:
Submittable
Defined in:
lib/actionview_attribute_builders/attribute_builders/button.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value = nil, options = {}, object, object_name, template_object) ⇒ Button

Returns a new instance of Button.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/actionview_attribute_builders/attribute_builders/button.rb', line 12

def initialize(value = nil, options = {}, object, object_name, template_object)
  @object_name = object_name
  @object = object
  @template_object = template_object
  @value = value
  @options = options

  case @value
  when Hash
    @options = @value
    @value = nil
  when Symbol
    @options = { name: @template_object.field_name(@value), id: @template_object.field_id(@value) }.merge!(@options.to_h)
    @value = nil
  end

  @value ||= submit_default_value

  formmethod = @options[:formmethod]
  if formmethod.present? && !/post|get/i.match?(formmethod) && !@options.key?(:name) && !@options.key?(:value)
    @options.merge! formmethod: :post, name: "_method", value: formmethod
  end
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



10
11
12
# File 'lib/actionview_attribute_builders/attribute_builders/button.rb', line 10

def value
  @value
end

Instance Method Details

#html_attributesObject



36
37
38
# File 'lib/actionview_attribute_builders/attribute_builders/button.rb', line 36

def html_attributes
  @options
end