Skip to content

Commit 4ac237d

Browse files
select existing article status if any, in Getting Started Guide -- Fixes rails#45028 (mostly) (rails#49010)
* select existing article status if any In the Getting Started guide, in the dropdown for an article or comment's status, pre-selecting `public` will make _all_ articles seem `public` even if their status is really something else -- even `nil`. This was reported in issue rails#45028. Selecting `article.status || 'public'` instead will fix this, in _most_ cases. Pre-existing articles with `nil` status will show up as `public`, but if the form is submitted, they will indeed become `public`. This commit makes that change, and adds text to explain why it is done. * Simplify wording of changes to Getting Started Co-authored-by: Rafael Mendonça França <[email protected]>
1 parent 704256e commit 4ac237d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

guides/source/getting_started.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1917,12 +1917,12 @@ Our blog has <%= Article.public_count %> articles and counting!
19171917
<%= link_to "New Article", new_article_path %>
19181918
```
19191919

1920-
To finish up, we will add a select box to the forms, and let the user select the status when they create a new article or post a new comment. We can also specify the default status as `public`. In `app/views/articles/_form.html.erb`, we can add:
1920+
To finish up, we will add a select box to the forms, and let the user select the status when they create a new article or post a new comment. We can also select the status of the object, or a default of `public` if it hasn't been set yet. In `app/views/articles/_form.html.erb`, we can add:
19211921

19221922
```html+erb
19231923
<div>
19241924
<%= form.label :status %><br>
1925-
<%= form.select :status, ['public', 'private', 'archived'], selected: 'public' %>
1925+
<%= form.select :status, ['public', 'private', 'archived'], selected: article.status || 'public' %>
19261926
</div>
19271927
```
19281928

0 commit comments

Comments
 (0)