Skip to content

Commit

Permalink
select existing article status if any, in Getting Started Guide -- Fixes
Browse files Browse the repository at this point in the history
 #45028 (mostly) (#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 #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 <rafael@rubyonrails.org>
  • Loading branch information
davearonson and rafaelfranca committed Aug 24, 2023
1 parent 704256e commit 4ac237d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions guides/source/getting_started.md
Expand Up @@ -1917,12 +1917,12 @@ Our blog has <%= Article.public_count %> articles and counting!
<%= link_to "New Article", new_article_path %>
```

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:
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:

```html+erb
<div>
<%= form.label :status %><br>
<%= form.select :status, ['public', 'private', 'archived'], selected: 'public' %>
<%= form.select :status, ['public', 'private', 'archived'], selected: article.status || 'public' %>
</div>
```

Expand Down

0 comments on commit 4ac237d

Please sign in to comment.