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
- #error_message_on(method, *args) ⇒ Object
- #error_messages(options = {}) ⇒ Object
- #fields_for(record_or_name_or_array, *args, &block) ⇒ 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.
726 727 728 729 730 731 732 733 734 735 736 |
# File 'lib/action_view/helpers/form_helper.rb', line 726 def initialize(object_name, object, template, , proc) @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.
724 725 726 |
# File 'lib/action_view/helpers/form_helper.rb', line 724 def object @object end |
#object_name ⇒ Object
Returns the value of attribute object_name.
724 725 726 |
# File 'lib/action_view/helpers/form_helper.rb', line 724 def object_name @object_name end |
#options ⇒ Object
Returns the value of attribute options.
724 725 726 |
# File 'lib/action_view/helpers/form_helper.rb', line 724 def @options end |
Instance Method Details
#check_box(method, options = {}, checked_value = "1", unchecked_value = "0") ⇒ Object
777 778 779 |
# File 'lib/action_view/helpers/form_helper.rb', line 777 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
379 380 381 |
# File 'lib/action_view/helpers/form_options_helper.rb', line 379 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
888 889 890 |
# File 'lib/action_view/helpers/date_helper.rb', line 888 def date_select(method, = {}, = {}) @template.date_select(@object_name, method, .merge(:object => @object), ) end |
#datetime_select(method, options = {}, html_options = {}) ⇒ Object
896 897 898 |
# File 'lib/action_view/helpers/date_helper.rb', line 896 def datetime_select(method, = {}, = {}) @template.datetime_select(@object_name, method, .merge(:object => @object), ) end |
#error_message_on(method, *args) ⇒ Object
785 786 787 |
# File 'lib/action_view/helpers/form_helper.rb', line 785 def (method, *args) @template.(@object, method, *args) end |
#error_messages(options = {}) ⇒ Object
789 790 791 |
# File 'lib/action_view/helpers/form_helper.rb', line 789 def ( = {}) @template.(@object_name, ()) end |
#fields_for(record_or_name_or_array, *args, &block) ⇒ Object
747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 |
# File 'lib/action_view/helpers/form_helper.rb', line 747 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 case record_or_name_or_array when String, Symbol name = "#{object_name}#{index}[#{record_or_name_or_array}]" 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 |
#label(method, text = nil, options = {}) ⇒ Object
773 774 775 |
# File 'lib/action_view/helpers/form_helper.rb', line 773 def label(method, text = nil, = {}) @template.label(@object_name, method, text, ()) end |
#radio_button(method, tag_value, options = {}) ⇒ Object
781 782 783 |
# File 'lib/action_view/helpers/form_helper.rb', line 781 def (method, tag_value, = {}) @template.(@object_name, method, tag_value, ()) end |
#select(method, choices, options = {}, html_options = {}) ⇒ Object
375 376 377 |
# File 'lib/action_view/helpers/form_options_helper.rb', line 375 def select(method, choices, = {}, = {}) @template.select(@object_name, method, choices, (), @default_options.merge()) end |
#submit(value = "Save changes", options = {}) ⇒ Object
793 794 795 |
# File 'lib/action_view/helpers/form_helper.rb', line 793 def submit(value = "Save changes", = {}) @template.submit_tag(value, .reverse_merge(:id => "#{object_name}_submit")) end |
#time_select(method, options = {}, html_options = {}) ⇒ Object
892 893 894 |
# File 'lib/action_view/helpers/date_helper.rb', line 892 def time_select(method, = {}, = {}) @template.time_select(@object_name, method, .merge(:object => @object), ) end |
#time_zone_select(method, priority_zones = nil, options = {}, html_options = {}) ⇒ Object
383 384 385 |
# File 'lib/action_view/helpers/form_options_helper.rb', line 383 def time_zone_select(method, priority_zones = nil, = {}, = {}) @template.time_zone_select(@object_name, method, priority_zones, (), @default_options.merge()) end |