Permalink
Browse files

Allow options to be passed down to semantic_fields_for.

Signed-off-by: Justin French <justin@indent.com.au>
  • Loading branch information...
1 parent 4baa492 commit d054316332fc319111d806eb7e73a6f43d6c8bed @josevalim josevalim committed with justinfrench Mar 16, 2009
Showing with 14 additions and 3 deletions.
  1. +4 −3 lib/formtastic.rb
  2. +10 −0 spec/formtastic_spec.rb
View
@@ -221,7 +221,8 @@ def inputs(*args, &block)
html_options[:class] ||= "inputs"
if fields_for_object = html_options.delete(:for)
- inputs_for_nested_attributes(fields_for_object, args << html_options, &block)
+ inputs_for_nested_attributes(fields_for_object, html_options.except(:name, :id, :class),
+ args << html_options, &block)
elsif block_given?
field_set_and_list_wrapping(html_options, &block)
else
@@ -298,7 +299,7 @@ def semantic_fields_for(record_or_name_or_array, *args, &block)
# Deals with :for option when it's supplied to inputs methods.
# It should raise an error if a block with arity zero is given.
#
- def inputs_for_nested_attributes(fields_for_object, inputs_args, &block)
+ def inputs_for_nested_attributes(fields_for_object, options, inputs_args, &block)
fields_for_block = if block_given?
raise ArgumentError, 'You gave :for option with a block to inputs method, ' <<
'but the block does not accept any argument.' if block.arity <= 0
@@ -308,7 +309,7 @@ def inputs_for_nested_attributes(fields_for_object, inputs_args, &block)
proc { |f| f.inputs(*inputs_args) }
end
- semantic_fields_for(*Array(fields_for_object), &fields_for_block)
+ semantic_fields_for(*(Array(fields_for_object) << options), &fields_for_block)
end
# Ensure :object => @object is set before sending the options down to the Rails layer.
View
@@ -2222,6 +2222,16 @@ def custom(arg1, arg2, options = {})
'but the block does not accept any argument.')
end
end
+
+ it 'should pass options down to semantic_fields_for' do
+ @bob.stub!(:column_for_attribute).and_return(mock('column', :type => :string, :limit => 255))
+
+ semantic_form_for(@new_post) do |builder|
+ builder.inputs :index => 10, :for => [:author, @bob] do |bob_builder|
+ bob_builder.instance_variable_get('@default_options').should == { :index => 10 }
+ end
+ end
+ end
end
describe 'when a :name option is provided' do

0 comments on commit d054316

Please sign in to comment.