module NestedForm
module ViewHelper
def nested_form_for(*args, &block)
options = args.extract_options!.reverse_merge(:builder => NestedForm::Builder)
form_for(*(args << options), &block) << after_nested_form_callbacks
end
if defined?(NestedForm::SimpleBuilder)
def simple_nested_form_for(*args, &block)
options = args.extract_options!.reverse_merge(:builder => NestedForm::SimpleBuilder)
simple_form_for(*(args << options), &block) << after_nested_form_callbacks
end
end
if defined?(NestedForm::FormtasticBuilder)
def semantic_nested_form_for(*args, &block)
options = args.extract_options!.reverse_merge(:builder => NestedForm::FormtasticBuilder)
semantic_form_for(*(args << options), &block) << after_nested_form_callbacks
end
end
def after_nested_form(association, &block)
@associations ||= []
@after_nested_form_callbacks ||= []
unless @associations.include?(association)
@associations << association
@after_nested_form_callbacks << block
end
end
private
def after_nested_form_callbacks
@after_nested_form_callbacks ||= []
fields = []
while callback = @after_nested_form_callbacks.shift
fields << callback.call
end
fields.join(" ").html_safe
end
end
end
对于像这样的代码
simple_form_for(*(args << options), &block) << after_nested_form_callbacks
谁能解释一下 << 是什么意思啊?我知道<<有字符串加的意思还有 Singleton class definition. 但这里我看得不是太懂,请指教了. 谢谢