# File lib/action_view/helpers/form_helper.rb, line 1110 def self.model_name @model_name ||= Struct.new(:partial_path).new(name.demodulize.underscore.sub!(/_builder$/, '')) end
# File lib/action_view/helpers/form_helper.rb, line 1118 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
# File lib/action_view/helpers/form_helper.rb, line 1182 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
# File lib/action_view/helpers/form_options_helper.rb, line 614 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
# File lib/action_view/helpers/date_helper.rb, line 968 def date_select(method, options = {}, html_options = {}) @template.date_select(@object_name, method, objectify_options(options), html_options) end
# File lib/action_view/helpers/date_helper.rb, line 976 def datetime_select(method, options = {}, html_options = {}) @template.datetime_select(@object_name, method, objectify_options(options), html_options) end
# File lib/action_view/helpers/form_helper.rb, line 1143 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}[#{ActiveModel::Naming.singular(object)}]" args.unshift(object) else object = record_or_name_or_array name = "#{object_name}#{index}[#{ActiveModel::Naming.singular(object)}]" args.unshift(object) end @template.fields_for(name, *args, &block) end
# File lib/action_view/helpers/form_options_helper.rb, line 618 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
# File lib/action_view/helpers/form_helper.rb, line 1178 def label(method, text = nil, options = {}, &block) @template.label(@object_name, method, text, objectify_options(options), &block) end
# File lib/action_view/helpers/form_options_helper.rb, line 610 def select(method, choices, options = {}, html_options = {}) @template.select(@object_name, method, choices, objectify_options(options), @default_options.merge(html_options)) end
Add the submit button for the given form. When no value is given, it checks if the object is a new resource or not to create the proper label:
<%= form_for @post do |f| %> <%= f.submit %> <% end %>
In the example above, if @post is a new record, it will use "Create Post" as submit button label, otherwise, it uses "Update Post".
Those labels can be customized using I18n, under the helpers.submit key and accept the %{model} as translation interpolation:
en: helpers: submit: create: "Create a %{model}" update: "Confirm changes to %{model}"
It also searches for a key specific for the given object:
en: helpers: submit: post: create: "Add %{model}"
# File lib/action_view/helpers/form_helper.rb, line 1222 def submit(value=nil, options={}) value, options = nil, value if value.is_a?(Hash) value ||= submit_default_value @template.submit_tag(value, options.reverse_merge(:id => "#{object_name}_submit")) end
# File lib/action_view/helpers/date_helper.rb, line 972 def time_select(method, options = {}, html_options = {}) @template.time_select(@object_name, method, objectify_options(options), html_options) end
# File lib/action_view/helpers/form_options_helper.rb, line 622 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
Generated with the Darkfish Rdoc Generator 2.