Class: ActionView::Helpers::FormBuilder::PropertySetFormBuilderProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/property_sets/action_view_extension.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(property_set, template, object_name, object) ⇒ PropertySetFormBuilderProxy

Returns a new instance of PropertySetFormBuilderProxy.


9
10
11
12
13
14
# File 'lib/property_sets/action_view_extension.rb', line 9

def initialize(property_set, template, object_name, object)
  @property_set = property_set
  @template     = template
  @object_name  = object_name
  @object       = object
end

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object


7
8
9
# File 'lib/property_sets/action_view_extension.rb', line 7

def object
  @object
end

#object_nameObject (readonly)

Returns the value of attribute object_name


7
8
9
# File 'lib/property_sets/action_view_extension.rb', line 7

def object_name
  @object_name
end

#property_setObject (readonly)

Returns the value of attribute property_set


7
8
9
# File 'lib/property_sets/action_view_extension.rb', line 7

def property_set
  @property_set
end

#templateObject (readonly)

Returns the value of attribute template


7
8
9
# File 'lib/property_sets/action_view_extension.rb', line 7

def template
  @template
end

Instance Method Details

#check_box(property, options = {}, checked_value = "1", unchecked_value = "0") ⇒ Object


16
17
18
19
20
21
# File 'lib/property_sets/action_view_extension.rb', line 16

def check_box(property, options = {}, checked_value = "1", unchecked_value = "0")
  options = prepare_options(property, options) do |properties|
    properties.send("#{property}?")
  end
  template.check_box(object_name, property, options, checked_value, unchecked_value)
end

#hidden_field(property, options = {}) ⇒ Object


35
36
37
38
39
40
41
# File 'lib/property_sets/action_view_extension.rb', line 35

def hidden_field(property, options = {})
  options = prepare_id_name(property, options)
  unless options.keys.include?(:value)
    options[:value] = cast_boolean(options[:object].send(property_set).send(property))
  end
  template.hidden_field(object_name, property, options)
end

#radio_button(property, checked_value = "1", options = {}) ⇒ Object


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

def radio_button(property, checked_value = "1", options = {})
  options[:id] ||= "#{object_name}_#{property_set}_#{property}_#{checked_value}"
  options = prepare_options(property, options) do |properties|
    properties.send("#{property}") == checked_value
  end
  template.radio_button(object_name, property, checked_value, options)
end

#select(property, choices, options = {}, html_options = {}) ⇒ Object


43
44
45
46
47
# File 'lib/property_sets/action_view_extension.rb', line 43

def select(property, choices, options = {}, html_options = {})
  options = prepare_id_name(property, options)
  current_value = options[:object].send(property_set).send(property)
  template.select("#{object_name}[#{property_set}]", property, choices, { :selected => current_value }, html_options )
end

#text_field(property, options = {}) ⇒ Object


31
32
33
# File 'lib/property_sets/action_view_extension.rb', line 31

def text_field(property, options = {})
  template.text_field(object_name, property, prepare_id_name(property, options))
end