我希望这是一个简单的问题 - 我有以下帮助代码:
module ApplicationHelper
def add_feature_fields(feature_types, object_form_builder, actions_visible)
feature_types.length.times {object_form_builder.object.features.build}
i = 0
fields = object_form_builder.fields_for :features do |features_builder|
render :partial => "features/fixed_feature", :locals => {:feature => features_builder, :fixed_feature_type => feature_types[i], :form_actions_visible => actions_visible}
i = i + 1
end
end
end
代码按预期工作,除了行i = i + 1
。出于某种原因,这似乎打破了循环,并且没有渲染任何内容。显然,我以某种方式做错了——也许 fields_for 不是一个正常的循环?
每次循环运行时,如何将 i 增加 1?