Skip to content

Commit 9f98cf5

Browse files
Rework form helper example to use Person.new
The previous change 92a3c8d improved this example, but calling .create + #valid? ends up running validations twice, and we don't want to showcase that. Lets use the normal use case of building a new object and calling #save on it, which is what a basic scaffold with Active Record does. [ci skip]
1 parent 3064533 commit 9f98cf5

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

actionview/lib/action_view/helpers/form_helper.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ module Helpers
6767
#
6868
# In particular, thanks to the conventions followed in the generated field names, the
6969
# controller gets a nested hash <tt>params[:person]</tt> with the person attributes
70-
# set in the form. That hash is ready to be passed to <tt>Person.create</tt>:
70+
# set in the form. That hash is ready to be passed to <tt>Person.new</tt>:
7171
#
72-
# @person = Person.create(params[:person])
73-
# if @person.valid?
72+
# @person = Person.new(params[:person])
73+
# if @person.save
7474
# # success
7575
# else
7676
# # error handling

0 commit comments

Comments
 (0)