Skip to content

Commit bf69c3f

Browse files
committed
Implement review fixes. Fix links.
1 parent b3558b6 commit bf69c3f

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

ruby_on_rails/forms_and_authentication/form_basics.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ The first line tells us which HTTP method was used and which route the form went
4747

4848
You'll find yourself looking at this server output a lot when you start building forms. It'll keep you sane because it tells you exactly what the browser sent back to your application so you can see if there's been a... misunderstanding.
4949

50-
### Railsifying your form - Making forms input into params
50+
### Railsifying your form by making forms input into params
5151

5252
Each one of these inputs is structured slightly differently, but there are some commonalities. One important thing to note is the `name` attribute that you can give to an input tag. In Rails, that's very important. The `name` attribute tells Rails what it should call the stuff you entered in that input field when it creates the `params` hash. For instance,
5353

@@ -276,9 +276,8 @@ At this point, you should have a solid understanding of how forms work in genera
276276

277277
The following questions are an opportunity to reflect on key topics in this lesson. If you can't answer a question, click on it to review the material, but keep in mind you are not expected to memorize or master this knowledge.
278278

279-
- [What is a CSRF Token and why is it necessary?](#railsifying-your-form)
280-
- [What is the `name` attribute of a form input element and what does it do?](#making-forms-into-params)
281-
- [How do you nest attributes under a single hash in `params`?](#making-forms-into-params)
279+
- [What is the `name` attribute of a form input element and what does it do?](#railsifying-your-form-by-making-forms-input-into-params)
280+
- [How do you nest attributes under a single hash in `params`?](#railsifying-your-form-by-making-forms-input-into-params)
282281
- [How do you pass `form_with` a model object?](#using-models-with-the-form_with-helper)
283282
- [How do you access errors for a failed-to-save model object?](#forms-and-validations)
284283
- [How do Rails forms make PATCH or DELETE requests?](#making-patch-and-delete-submissions)

ruby_on_rails/forms_and_authentication/project_forms.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ The first form you build will be mostly HTML (remember that stuff at all?). Bui
3434

3535
1. Create the proper input tags for your user's fields (email, username and password). Use the proper password input for "password". Be sure to specify the `name` attribute for these inputs. Make label tags which correspond to each field.
3636

37-
1. CSRF Safety:
38-
From Rails 7, Turbo is enabled by default in new apps. Turbo intercepts form submission and makes a partial XHR request instead of a standard HTTP request with full page reload. To get a better grasp of Rails protection against [cross-site request forgery](https://en.wikipedia.org/wiki/Cross-site_request_forgery), let's take a small detour and disable Turbo for this form by setting the data attribute `data-turbo=false`.
37+
1. For CSRF safety with Rails 7, Turbo is enabled by default in new apps. Turbo intercepts form submission and makes a partial XHR request instead of a standard HTTP request with full page reload. To get a better grasp of Rails protection against [cross-site request forgery](https://en.wikipedia.org/wiki/Cross-site_request_forgery), let's take a short detour and disable Turbo for this form by setting the data attribute `data-turbo=false`.
3938
In the dev tools network tab, compare the request type with and without the `data-turbo=false` attribute to confirm it works as expected.
4039

4140
1. Submit your form and view the server output. The request should be intercepted before reaching your controller and the server will throw a CSRF error `ActionController::InvalidAuthenticityToken (Can't verify CSRF token authenticity.)`.
@@ -117,11 +116,9 @@ Above, we asked to disable Turbo for the sake of the exercise.
117116

118117
1. Re-enable form submission with Turbo by removing the `data-turbo=false` attribute on the form tag, then also remove the hidden input with CSRF token tag and submit.
119118

120-
No more CSRF error!?!
121-
The from is now submitted with Turbo, yet Rails still protects you by verifying a CSRF token. Where does this token comes from?
119+
No more CSRF error?!
122120

123-
1. Check your inspector and your `application.html.erb` template. See a CSRF token that s always available?
124-
Remove this one too from `application.html.erb`, and verify that the server hits back with a CSRF error.
121+
1. The from is now submitted with Turbo, yet Rails still protects you by verifying a CSRF token. Where does this token comes from? Check your inspector and your `application.html.erb` template. Can you find a CSRF token that is always available? Remove this one too from `application.html.erb`, and verify that the server hits back with a CSRF error.
125122

126123
1. Reinstate the CSRF token tag in both places and carry on.
127124

0 commit comments

Comments
 (0)