- #
- B
- C
- D
- E
- F
- G
- H
- L
- M
- N
- R
- S
- T
[R] | multipart | |
[R] | multipart? | |
[RW] | object | |
[RW] | object_name | |
[RW] | options | |
[R] | parent_builder |
# File actionpack/lib/action_view/helpers/form_helper.rb, line 1266 def initialize(object_name, object, template, options, proc) @nested_child_index = {} @object_name, @object, @template, @options, @proc = object_name, object, template, options, proc @parent_builder = options[:parent_builder] @default_options = @options ? @options.slice(:index, :namespace) : {} if @object_name.to_s.match(%r\[\]$/) 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 @multipart = nil 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.button %> <% 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: button: create: "Create a %{model}" update: "Confirm changes to %{model}"
It also searches for a key specific for the given object:
en: helpers: button: post: create: "Add %{model}"
# File actionpack/lib/action_view/helpers/form_options_helper.rb, line 645 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
Source: on GitHub
|# File actionpack/lib/action_view/helpers/form_helper.rb, line 1293 def fields_for(record_name, record_object = nil, fields_options = {}, &block) fields_options, record_object = record_object, nil if record_object.is_a?(Hash) && record_object.extractable_options? fields_options[:builder] ||= options[:builder] fields_options[:parent_builder] = self fields_options[:namespace] = fields_options[:parent_builder].options[:namespace] case record_name when String, Symbol if nested_attributes_association?(record_name) return fields_for_with_nested_attributes(record_name, record_object, fields_options, block) end else record_object = record_name.is_a?(Array) ? record_name.last : record_name record_name = ActiveModel::Naming.param_key(record_object) end index = if options.has_key?(:index) "[#{options[:index]}]" elsif defined?(@auto_index) self.object_name = @object_name.to_s.sub(%r\[\]$/,"") "[#{@auto_index}]" end record_name = "#{object_name}#{index}[#{record_name}]" @template.fields_for(record_name, record_object, fields_options, &block) end
# File actionpack/lib/action_view/helpers/form_options_helper.rb, line 649 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
Source: on GitHub
|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 actionpack/lib/action_view/helpers/form_options_helper.rb, line 653 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