@@ -5,10 +5,13 @@ class Form < AbstractForm
55 delegate :id , :_destroy , :persisted? , to : :model
66 attr_reader :association_name , :parent , :model , :proc
77
8- def initialize ( assoc_name , parent , proc , model = nil )
8+ def initialize ( assoc_name , parent , proc , options = { } )
99 @association_name = assoc_name
1010 @parent = parent
11+
12+ model = options unless options . is_a? ( Hash )
1113 @model = model || build_model
14+
1215 @forms = [ ]
1316 instance_eval ( &proc ) if proc
1417 enable_autosave
@@ -22,11 +25,9 @@ def association(name, options = {}, &block)
2225 define_singleton_method ( name ) { instance_variable_get ( "@#{ name } " ) . models }
2326 define_singleton_method ( "#{ name } _attributes=" ) { }
2427
25- definition = FormDefinition . new ( name , block , options )
26- definition . parent = @model
27- definition . to_form . tap do |nested_form |
28- forms << nested_form
29- instance_variable_set ( "@#{ name } " , nested_form )
28+ FormDefinition . new ( name , block , options ) . build_for ( @model ) . tap do |form |
29+ forms << form
30+ instance_variable_set ( "@#{ name } " , form )
3031 end
3132 end
3233
0 commit comments