aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/lib/action_view/helpers/form_helper.rb
diff options
context:
space:
mode:
authorKarol Galanciak <karol.galanciak@gmail.com>2015-04-05 21:51:19 +0200
committerKarol Galanciak <karol.galanciak@gmail.com>2015-04-05 21:51:19 +0200
commita813fa09a86ec522b43f16d137bd99e0a43985f5 (patch)
treec6d426abb32556f5154a6ea93e0deca23e3a76e6 /actionview/lib/action_view/helpers/form_helper.rb
parent9040699aed64a725cc66461d63f794abc2f13afc (diff)
downloadrails-a813fa09a86ec522b43f16d137bd99e0a43985f5.tar.gz
rails-a813fa09a86ec522b43f16d137bd99e0a43985f5.tar.bz2
rails-a813fa09a86ec522b43f16d137bd99e0a43985f5.zip
Accept lambda as child_index option in #fields_for method
Diffstat (limited to 'actionview/lib/action_view/helpers/form_helper.rb')
-rw-r--r--actionview/lib/action_view/helpers/form_helper.rb6
1 files changed, 5 insertions, 1 deletions
diff --git a/actionview/lib/action_view/helpers/form_helper.rb b/actionview/lib/action_view/helpers/form_helper.rb
index 891cc53765..ece117b547 100644
--- a/actionview/lib/action_view/helpers/form_helper.rb
+++ b/actionview/lib/action_view/helpers/form_helper.rb
@@ -1928,7 +1928,11 @@ module ActionView
explicit_child_index = options[:child_index]
output = ActiveSupport::SafeBuffer.new
association.each do |child|
- options[:child_index] = nested_child_index(name) unless explicit_child_index
+ if explicit_child_index
+ options[:child_index] = explicit_child_index.call if explicit_child_index.respond_to?(:call)
+ else
+ options[:child_index] = nested_child_index(name)
+ end
output << fields_for_nested_model("#{name}[#{options[:child_index]}]", child, options, block)
end
output