Class: ActionView::Helpers::FormBuilder
- Defined in:
- lib/action_view/helpers/form_helper.rb,
lib/action_view/helpers/date_helper.rb,
lib/action_view/helpers/form_options_helper.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#object ⇒ Object
Returns the value of attribute object.
-
#object_name ⇒ Object
Returns the value of attribute object_name.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #check_box(method, options = {}, checked_value = "1", unchecked_value = "0") ⇒ Object
- #collection_select(method, collection, value_method, text_method, options = {}, html_options = {}) ⇒ Object
- #date_select(method, options = {}, html_options = {}) ⇒ Object
- #datetime_select(method, options = {}, html_options = {}) ⇒ Object
- #emitted_hidden_id? ⇒ Boolean
- #error_message_on(method, *args) ⇒ Object
- #error_messages(options = {}) ⇒ Object
- #fields_for(record_or_name_or_array, *args, &block) ⇒ Object
- #grouped_collection_select(method, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {}) ⇒ Object
- #hidden_field(method, options = {}) ⇒ Object
-
#initialize(object_name, object, template, options, proc) ⇒ FormBuilder
constructor
A new instance of FormBuilder.
- #label(method, text = nil, options = {}) ⇒ Object
- #radio_button(method, tag_value, options = {}) ⇒ Object
- #select(method, choices, options = {}, html_options = {}) ⇒ Object
- #submit(value = "Save changes", options = {}) ⇒ Object
- #time_select(method, options = {}, html_options = {}) ⇒ Object
- #time_zone_select(method, priority_zones = nil, options = {}, html_options = {}) ⇒ Object
Constructor Details
#initialize(object_name, object, template, options, proc) ⇒ FormBuilder
Returns a new instance of FormBuilder.
973 974 975 976 977 978 979 980 981 982 983 984 |
# File 'lib/action_view/helpers/form_helper.rb', line 973 def initialize(object_name, object, template, , proc) @nested_child_index = {} @object_name, @object, @template, @options, @proc = object_name, object, template, , proc @default_options = @options ? @options.slice(:index) : {} if @object_name.to_s.match(/\[\]$/) if object ||= @template.instance_variable_get("@#{Regexp.last_match.pre_match}") and object.respond_to?(:to_param) @auto_index = object.to_param else raise ArgumentError, "object[] naming but object param and @object var don't exist or don't respond to to_param: #{object.inspect}" end end end |
Instance Attribute Details
#object ⇒ Object
Returns the value of attribute object.
971 972 973 |
# File 'lib/action_view/helpers/form_helper.rb', line 971 def object @object end |
#object_name ⇒ Object
Returns the value of attribute object_name.
971 972 973 |
# File 'lib/action_view/helpers/form_helper.rb', line 971 def object_name @object_name end |
#options ⇒ Object
Returns the value of attribute options.
971 972 973 |
# File 'lib/action_view/helpers/form_helper.rb', line 971 def @options end |
Instance Method Details
#check_box(method, options = {}, checked_value = "1", unchecked_value = "0") ⇒ Object
1038 1039 1040 |
# File 'lib/action_view/helpers/form_helper.rb', line 1038 def check_box(method, = {}, checked_value = "1", unchecked_value = "0") @template.check_box(@object_name, method, (), checked_value, unchecked_value) end |
#collection_select(method, collection, value_method, text_method, options = {}, html_options = {}) ⇒ Object
586 587 588 |
# File 'lib/action_view/helpers/form_options_helper.rb', line 586 def collection_select(method, collection, value_method, text_method, = {}, = {}) @template.collection_select(@object_name, method, collection, value_method, text_method, (), @default_options.merge()) end |
#date_select(method, options = {}, html_options = {}) ⇒ Object
976 977 978 |
# File 'lib/action_view/helpers/date_helper.rb', line 976 def date_select(method, = {}, = {}) @template.date_select(@object_name, method, (), ) end |
#datetime_select(method, options = {}, html_options = {}) ⇒ Object
984 985 986 |
# File 'lib/action_view/helpers/date_helper.rb', line 984 def datetime_select(method, = {}, = {}) @template.datetime_select(@object_name, method, (), ) end |
#emitted_hidden_id? ⇒ Boolean
1063 1064 1065 |
# File 'lib/action_view/helpers/form_helper.rb', line 1063 def emitted_hidden_id? @emitted_hidden_id end |
#error_message_on(method, *args) ⇒ Object
1051 1052 1053 |
# File 'lib/action_view/helpers/form_helper.rb', line 1051 def (method, *args) @template.(@object || @object_name, method, *args) end |
#error_messages(options = {}) ⇒ Object
1055 1056 1057 |
# File 'lib/action_view/helpers/form_helper.rb', line 1055 def ( = {}) @template.(@object_name, ()) end |
#fields_for(record_or_name_or_array, *args, &block) ⇒ Object
999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 |
# File 'lib/action_view/helpers/form_helper.rb', line 999 def fields_for(record_or_name_or_array, *args, &block) if .has_key?(:index) index = "[#{[:index]}]" elsif defined?(@auto_index) self.object_name = @object_name.to_s.sub(/\[\]$/,"") index = "[#{@auto_index}]" else index = "" end if [:builder] args << {} unless args.last.is_a?(Hash) args.last[:builder] ||= [:builder] end case record_or_name_or_array when String, Symbol if nested_attributes_association?(record_or_name_or_array) return fields_for_with_nested_attributes(record_or_name_or_array, args, block) else name = "#{object_name}#{index}[#{record_or_name_or_array}]" end when Array object = record_or_name_or_array.last name = "#{object_name}#{index}[#{ActionController::RecordIdentifier.singular_class_name(object)}]" args.unshift(object) else object = record_or_name_or_array name = "#{object_name}#{index}[#{ActionController::RecordIdentifier.singular_class_name(object)}]" args.unshift(object) end @template.fields_for(name, *args, &block) end |
#grouped_collection_select(method, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {}) ⇒ Object
590 591 592 |
# File 'lib/action_view/helpers/form_options_helper.rb', line 590 def grouped_collection_select(method, collection, group_method, group_label_method, option_key_method, option_value_method, = {}, = {}) @template.grouped_collection_select(@object_name, method, collection, group_method, group_label_method, option_key_method, option_value_method, (), @default_options.merge()) end |
#hidden_field(method, options = {}) ⇒ Object
1046 1047 1048 1049 |
# File 'lib/action_view/helpers/form_helper.rb', line 1046 def hidden_field(method, = {}) @emitted_hidden_id = true if method == :id @template.hidden_field(@object_name, method, ()) end |
#label(method, text = nil, options = {}) ⇒ Object
1034 1035 1036 |
# File 'lib/action_view/helpers/form_helper.rb', line 1034 def label(method, text = nil, = {}) @template.label(@object_name, method, text, ()) end |
#radio_button(method, tag_value, options = {}) ⇒ Object
1042 1043 1044 |
# File 'lib/action_view/helpers/form_helper.rb', line 1042 def (method, tag_value, = {}) @template.(@object_name, method, tag_value, ()) end |
#select(method, choices, options = {}, html_options = {}) ⇒ Object
582 583 584 |
# File 'lib/action_view/helpers/form_options_helper.rb', line 582 def select(method, choices, = {}, = {}) @template.select(@object_name, method, choices, (), @default_options.merge()) end |
#submit(value = "Save changes", options = {}) ⇒ Object
1059 1060 1061 |
# File 'lib/action_view/helpers/form_helper.rb', line 1059 def submit(value = "Save changes", = {}) @template.submit_tag(value, .reverse_merge(:id => "#{object_name}_submit")) end |
#time_select(method, options = {}, html_options = {}) ⇒ Object
980 981 982 |
# File 'lib/action_view/helpers/date_helper.rb', line 980 def time_select(method, = {}, = {}) @template.time_select(@object_name, method, (), ) end |
#time_zone_select(method, priority_zones = nil, options = {}, html_options = {}) ⇒ Object
594 595 596 |
# File 'lib/action_view/helpers/form_options_helper.rb', line 594 def time_zone_select(method, priority_zones = nil, = {}, = {}) @template.time_zone_select(@object_name, method, priority_zones, (), @default_options.merge()) end |