Skip to content

Commit 1f62d1c

Browse files
committed
Fixed proc call when form with new record was initialized
As I guess from `FormDefinition#initialize`, `proc` is never set. In my case, it was always `nil` and for new records, the code evaluated `form.instance_eval(&proc)` where `proc` was nil. That lead to `ArgumentError: wrong number of arguments (0 for 1..3)`.
1 parent 097f3ef commit 1f62d1c

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/active_form/form_collection.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -134,19 +134,19 @@ def aggregate_form_errors
134134

135135
def fetch_models
136136
associated_records = parent.send(association_name)
137-
137+
138138
associated_records.each do |model|
139139
form = Form.new(association_name, parent, proc, model)
140140
forms << form
141-
form.instance_eval &proc
141+
form.instance_eval(&proc) if proc.present?
142142
end
143143
end
144144

145145
def initialize_models
146146
records.times do
147147
form = Form.new(association_name, parent, proc)
148148
forms << form
149-
form.instance_eval &proc
149+
form.instance_eval(&proc) if proc.present?
150150
end
151151
end
152152

@@ -178,4 +178,4 @@ def create_form
178178
end
179179
end
180180

181-
end
181+
end

0 commit comments

Comments
 (0)