Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Concat the output of inputs_for_nested_attributes to the template und…

…er rails3

Instead of returning the output the result needs to be added to the template
since the rails fields_for helper doesn't do this automatically. This can be
seen here: http://github.com/rails/rails/commit/7fadb3f2#L0R1081
  • Loading branch information...
commit 431333f25b16115760bbb018f889495fedb548e1 1 parent cedf4a7
@yabawock yabawock authored
Showing with 29 additions and 5 deletions.
  1. +11 −3 lib/formtastic.rb
  2. +1 −1  lib/formtastic/util.rb
  3. +17 −1 spec/inputs_spec.rb
View
14 lib/formtastic.rb
@@ -528,9 +528,17 @@ def inputs_for_nested_attributes(*args, &block) #:nodoc:
raise ArgumentError, 'You gave :for option with a block to inputs method, ' <<
'but the block does not accept any argument.' if block.arity <= 0
- proc { |f| return f.inputs(*args){ block.call(f) } }
+ Proc.new do |f|
+ contents = f.inputs(*args){ block.call(f) }
+ template.concat(contents) if ::Formtastic::Util.rails3?
+ contents
+ end
else
- proc { |f| return f.inputs(*args) }
+ Proc.new do |f|
+ contents = f.inputs(*args)
+ template.concat(contents) if ::Formtastic::Util.rails3?
+ contents
+ end
end
fields_for_args = [options.delete(:for), options.delete(:for_options) || {}].flatten
@@ -1321,7 +1329,7 @@ def field_set_and_list_wrapping(*args, &block) #:nodoc:
html_options.except(:builder, :parent)
)
- template.concat(fieldset) if block_given? && (!defined?(Rails::VERSION) || Rails::VERSION::MAJOR == 2)
+ template.concat(fieldset) if block_given? && !Formtastic::Util.rails3?
fieldset
end
View
2  lib/formtastic/util.rb
@@ -30,7 +30,7 @@ def rails3?
if defined?(ActionPack::VERSION::MAJOR)
ActionPack::VERSION::MAJOR
end
- version >= 3
+ !version.blank? && version >= 3
end
end
end
View
18 spec/inputs_spec.rb
@@ -82,7 +82,23 @@
output_buffer.should_not have_tag("form fieldset.inputs #author_login")
end
-
+
+ it 'should concat rendered nested inputs to the template under rails3' do
+ @bob.stub!(:column_for_attribute).and_return(mock('column', :type => :string, :limit => 255))
+ ::Formtastic::Util.stub!(:rails3?).and_return(true)
+
+ form = semantic_form_for(@new_post) do |builder|
+ builder.inputs :for => [:author, @bob] do |bob_builder|
+ concat(bob_builder.input(:login))
+ end
+ end
+
+ output_buffer.concat(form) if Formtastic::Util.rails3?
+ output_buffer.should have_tag("form fieldset.inputs #post_author_attributes_login")
+ output_buffer.should_not have_tag("form fieldset.inputs #author_login")
+
+ end
+
describe "as a symbol representing the association name" do
it 'should nest the inputs with an _attributes suffix on the association name' do
Please sign in to comment.
Something went wrong with that request. Please try again.