Class: ActionView::Helpers::FormBuilder

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(object_name, object, template, options, proc) ⇒ FormBuilder

Returns a new instance of FormBuilder.



929
930
931
932
933
934
935
936
937
938
939
940
# File 'lib/action_view/helpers/form_helper.rb', line 929

def initialize(object_name, object, template, options, proc)
  @nested_child_index = {}
  @object_name, @object, @template, @options, @proc = object_name, object, template, options, 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

#objectObject

Returns the value of attribute object.



927
928
929
# File 'lib/action_view/helpers/form_helper.rb', line 927

def object
  @object
end

#object_nameObject

Returns the value of attribute object_name.



927
928
929
# File 'lib/action_view/helpers/form_helper.rb', line 927

def object_name
  @object_name
end

#optionsObject

Returns the value of attribute options.



927
928
929
# File 'lib/action_view/helpers/form_helper.rb', line 927

def options
  @options
end

Instance Method Details

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



994
995
996
# File 'lib/action_view/helpers/form_helper.rb', line 994

def check_box(method, options = {}, checked_value = "1", unchecked_value = "0")
  @template.check_box(@object_name, method, objectify_options(options), checked_value, unchecked_value)
end

#collection_select(method, collection, value_method, text_method, options = {}, html_options = {}) ⇒ Object



587
588
589
# File 'lib/action_view/helpers/form_options_helper.rb', line 587

def collection_select(method, collection, value_method, text_method, options = {}, html_options = {})
  @template.collection_select(@object_name, method, collection, value_method, text_method, objectify_options(options), @default_options.merge(html_options))
end

#date_select(method, options = {}, html_options = {}) ⇒ Object



975
976
977
# File 'lib/action_view/helpers/date_helper.rb', line 975

def date_select(method, options = {}, html_options = {})
  @template.date_select(@object_name, method, objectify_options(options), html_options)
end

#datetime_select(method, options = {}, html_options = {}) ⇒ Object



983
984
985
# File 'lib/action_view/helpers/date_helper.rb', line 983

def datetime_select(method, options = {}, html_options = {})
  @template.datetime_select(@object_name, method, objectify_options(options), html_options)
end

#emitted_hidden_id?Boolean

Returns:

  • (Boolean)


1019
1020
1021
# File 'lib/action_view/helpers/form_helper.rb', line 1019

def emitted_hidden_id?
  @emitted_hidden_id
end

#error_message_on(method, *args) ⇒ Object



1007
1008
1009
# File 'lib/action_view/helpers/form_helper.rb', line 1007

def error_message_on(method, *args)
  @template.error_message_on(@object, method, *args)
end

#error_messages(options = {}) ⇒ Object



1011
1012
1013
# File 'lib/action_view/helpers/form_helper.rb', line 1011

def error_messages(options = {})
  @template.error_messages_for(@object_name, objectify_options(options))
end

#fields_for(record_or_name_or_array, *args, &block) ⇒ Object



955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
# File 'lib/action_view/helpers/form_helper.rb', line 955

def fields_for(record_or_name_or_array, *args, &block)
  if options.has_key?(:index)
    index = "[#{options[:index]}]"
  elsif defined?(@auto_index)
    self.object_name = @object_name.to_s.sub(/\[\]$/,"")
    index = "[#{@auto_index}]"
  else
    index = ""
  end

  if options[:builder]
    args << {} unless args.last.is_a?(Hash)
    args.last[:builder] ||= options[: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



591
592
593
# File 'lib/action_view/helpers/form_options_helper.rb', line 591

def grouped_collection_select(method, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {})
  @template.grouped_collection_select(@object_name, method, collection, group_method, group_label_method, option_key_method, option_value_method, objectify_options(options), @default_options.merge(html_options))
end

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



1002
1003
1004
1005
# File 'lib/action_view/helpers/form_helper.rb', line 1002

def hidden_field(method, options = {})
  @emitted_hidden_id = true if method == :id
  @template.hidden_field(@object_name, method, objectify_options(options))
end

#label(method, text = nil, options = {}) ⇒ Object



990
991
992
# File 'lib/action_view/helpers/form_helper.rb', line 990

def label(method, text = nil, options = {})
  @template.label(@object_name, method, text, objectify_options(options))
end

#radio_button(method, tag_value, options = {}) ⇒ Object



998
999
1000
# File 'lib/action_view/helpers/form_helper.rb', line 998

def radio_button(method, tag_value, options = {})
  @template.radio_button(@object_name, method, tag_value, objectify_options(options))
end

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



583
584
585
# File 'lib/action_view/helpers/form_options_helper.rb', line 583

def select(method, choices, options = {}, html_options = {})
  @template.select(@object_name, method, choices, objectify_options(options), @default_options.merge(html_options))
end

#submit(value = "Save changes", options = {}) ⇒ Object



1015
1016
1017
# File 'lib/action_view/helpers/form_helper.rb', line 1015

def submit(value = "Save changes", options = {})
  @template.submit_tag(value, options.reverse_merge(:id => "#{object_name}_submit"))
end

#time_select(method, options = {}, html_options = {}) ⇒ Object



979
980
981
# File 'lib/action_view/helpers/date_helper.rb', line 979

def time_select(method, options = {}, html_options = {})
  @template.time_select(@object_name, method, objectify_options(options), html_options)
end

#time_zone_select(method, priority_zones = nil, options = {}, html_options = {}) ⇒ Object



595
596
597
# File 'lib/action_view/helpers/form_options_helper.rb', line 595

def time_zone_select(method, priority_zones = nil, options = {}, html_options = {})
  @template.time_zone_select(@object_name, method, priority_zones, objectify_options(options), @default_options.merge(html_options))
end