Skip to content

Commit

Permalink
Merge pull request #43233 from kiizerd/patch-1
Browse files Browse the repository at this point in the history
Reorder getting_started 8.3 to reduce confusion
  • Loading branch information
rafaelfranca committed Sep 20, 2021
2 parents dbc9456 + a2f9a63 commit 11254fb
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions guides/source/getting_started.md
Expand Up @@ -1714,7 +1714,35 @@ app/models/concerns

A given blog article might have various statuses - for instance, it might be visible to everyone (i.e. `public`), or only visible to the author (i.e. `private`). It may also be hidden to all but still retrievable (i.e. `archived`). Comments may similarly be hidden or visible. This could be represented using a `status` column in each model.

Within the `article` model, after running a migration to add a `status` column, you might add:
First, let's run the following migrations to add `status` to `Articles` and `Comments`:

```bash
$ bin/rails generate migration AddStatusToArticles status:string
$ bin/rails generate migration AddStatusToComments status:string
```

TIP: To learn more about migrations, see [Active Record Migrations](
active_record_migrations.html).

We also have to permit the `:status` key as part of the strong parameter, in `app/controllers/articles_controller.rb`:

```ruby
private
def article_params
params.require(:article).permit(:title, :body, :status)
end
```

and in `app/controllers/comments_controller.rb`:

```ruby
private
def comment_params
params.require(:comment).permit(:commenter, :body, :status)
end
```

Within the `article` model, after running a migration to add a `status` column, you would add:

```ruby
class Article < ApplicationRecord
Expand Down Expand Up @@ -1885,34 +1913,6 @@ Our blog has <%= Article.public_count %> articles and counting!
<%= link_to "New Article", new_article_path %>
```

There are a few more steps to be carried out before our application works with the addition of `status` column. First, let's run the following migrations to add `status` to `Articles` and `Comments`:

```bash
$ bin/rails generate migration AddStatusToArticles status:string
$ bin/rails generate migration AddStatusToComments status:string
```

TIP: To learn more about migrations, see [Active Record Migrations](
active_record_migrations.html).

We also have to permit the `:status` key as part of the strong parameter, in `app/controllers/articles_controller.rb`:

```ruby
private
def article_params
params.require(:article).permit(:title, :body, :status)
end
```

and in `app/controllers/comments_controller.rb`:

```ruby
private
def comment_params
params.require(:comment).permit(:commenter, :body, :status)
end
```

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:

```html+erb
Expand Down

0 comments on commit 11254fb

Please sign in to comment.