Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Commit

Permalink
use concat instead of returned string in fields_for
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanb committed Jan 12, 2010
1 parent 0d7ee17 commit d63c5aa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
9 changes: 6 additions & 3 deletions lib/nested_form/builder.rb
Expand Up @@ -4,8 +4,9 @@ def link_to_add(name, association)
@fields ||= {}
@template.after_nested_form do
model_object = object.class.reflect_on_association(association).klass.new
fields = fields_for(association, model_object, :child_index => "new_#{association}", &@fields[association])
@template.content_tag(:div, fields, :style => "display: none")
@template.concat('<div style="display: none">')
fields_for(association, model_object, :child_index => "new_#{association}", &@fields[association])
@template.concat('</div>')
end
@template.link_to(name, "javascript:void(0)", :class => "add_nested_fields", "data-association" => association)
end
Expand All @@ -22,7 +23,9 @@ def fields_for_with_nested_attributes(association, args, block)


def fields_for_nested_model(name, association, args, block)
@template.content_tag(:div, super, :class => "fields")
@template.concat('<div class="fields">')
super
@template.concat('</div>')
end
end
end
2 changes: 1 addition & 1 deletion lib/nested_form/view_helper.rb
Expand Up @@ -3,7 +3,7 @@ module ViewHelper
def nested_form_for(*args, &block)
options = args.extract_options!.reverse_merge(:builder => NestedForm::Builder)
form_for(*(args << options), &block)
concat(@after_nested_form_callback.call) if @after_nested_form_callback
@after_nested_form_callback.call if @after_nested_form_callback
end

def after_nested_form(&block)
Expand Down
12 changes: 6 additions & 6 deletions spec/nested_form/builder_spec.rb
Expand Up @@ -20,16 +20,16 @@
it "should wrap nested fields each in a div with class" do
2.times { @project.tasks.build }
@builder.fields_for(:tasks) do
"Task"
end.should == '<div class="fields">Task</div><div class="fields">Task</div>'
@template.concat("Task")
end
@template.output_buffer.should == '<div class="fields">Task</div><div class="fields">Task</div>'
end

it "should add task fields to hidden div after form" do
content = nil
mock(@template).after_nested_form { |block| content = block.call }
@builder.fields_for(:tasks) { "Task" }
mock(@template).after_nested_form { |block| block.call }
@builder.fields_for(:tasks) { @template.concat("Task") }
@builder.link_to_add("Add", :tasks)
content.should == '<div style="display: none"><div class="fields">Task</div></div>'
@template.output_buffer.should == '<div style="display: none"><div class="fields">Task</div></div>'
end
end
end

0 comments on commit d63c5aa

Please sign in to comment.