Skip to content

Commit

Permalink
correct information about record identification
Browse files Browse the repository at this point in the history
The description claimed that `.new_record?` was used in `form_for` to derive the action and button text.
But in the code `.persisted?` is used for that purpose.

[ci skip]
  • Loading branch information
lxxxvi committed Oct 4, 2019
1 parent 5213213 commit f60bc89
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion guides/source/form_helpers.md
Expand Up @@ -317,7 +317,7 @@ form_with(model: @article, url: article_path(@article), method: "patch")
form_with(model: @article)
```

Notice how the short-style `form_with` invocation is conveniently the same, regardless of the record being new or existing. Record identification is smart enough to figure out if the record is new by asking `record.new_record?`. It also selects the correct path to submit to, and the name based on the class of the object.
Notice how the short-style `form_with` invocation is conveniently the same, regardless of the record being new or existing. Record identification is smart enough to figure out if the record is new by asking `record.persisted?`. It also selects the correct path to submit to, and the name based on the class of the object.

WARNING: When you're using STI (single-table inheritance) with your models, you can't rely on record identification on a subclass if only their parent class is declared a resource. You will have to specify `:url`, and `:scope` (the model name) explicitly.

Expand Down

0 comments on commit f60bc89

Please sign in to comment.