Skip to content

[RF-DOCS] Sign up guide #55254

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open

[RF-DOCS] Sign up guide #55254

wants to merge 16 commits into from

Conversation

excid3
Copy link
Contributor

@excid3 excid3 commented Jun 27, 2025

Motivation / Background

This is a continuation of the Getting Started guide.

Detail

After building the e-commerce store, this guide adds:

  • Sign up
  • Edit profile
  • Edit password
  • Change email address with email confirmation
  • Delete account
  • Admin role
  • Admin area for product management

Additional information

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Unrelated changes should be opened in separate PRs.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • Tests are added or updated if you fix a bug or add a feature.
  • CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.

cc @AmandaPerino

@rails-bot rails-bot bot added the docs label Jun 27, 2025
@AmandaPerino AmandaPerino added the rails foundation Rails Foundation PRs label Jun 27, 2025
@MatheusRich
Copy link
Contributor

@excid3 how does one get to this guide? Is it linked from the Getting Started one?

@p8
Copy link
Member

p8 commented Jun 27, 2025

@excid3
Copy link
Contributor Author

excid3 commented Jun 27, 2025

There are design changes coming so it will be done in a separate PR.

@AmandaPerino
Copy link
Contributor

AmandaPerino commented Jun 27, 2025

@MatheusRich @p8 Just like the /docs landing page we launched last year, we are building a Tutorial landing page where all of the tutorials, and all upcoming tutorials will live. (PR here.)
Tutorial Homepage r2a (1)

@MatheusRich
Copy link
Contributor

@AmandaPerino amazing! For anyone reviewing and wants to preview the results:

  1. Find the latest build preview in the GH action:
image
  1. Add /guides/sign_up_and_settings.html to the end of that URL


```ruby
namespace :settings do
resource :password, only: [:show, :update]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why show and not edit?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it was done to create a nice "/settings/password" path.

Like you, I was confused at first, but I eventually came to like the idea because it tells readers implicitly that forms do not always have to be on new or edit routes, and that they are not constricted by the framework.

Let's add that `update` action to the controller now.

```ruby#5-17
class Settings::PasswordsController < Settings::BaseController
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is using Settings::BaseController before we introduced it


### Users Controller & Views

We can then use this in the controller. Create `app/controllers/settings/users_controller.rb` and add the following:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a biggie, but I found it a bit confusing to mix the other settings (which seems mostly personal) with admin stuff. I'd suggest an admin namespace, but that would generate a lot of rework.

Copy link
Contributor

@MatheusRich MatheusRich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great tutorial, as always @excid3! So easy to follow and yet very comprehensive! I love how clean the code is and all the little details you put here and there. It shows your deep understanding of the Rails-way. It teaches so much more than the title says. Well done!

@p8
Copy link
Member

p8 commented Jun 28, 2025

@MatheusRich @p8 Just like the /docs landing page we launched last year, we are building a Tutorial landing page where all of the tutorials, and all upcoming tutorials will live.

@AmandaPerino That looks great!
If these tutorials are part of https://github.com/rails/website would it make sense to move this PR there as well?

```erb
<h1>Password</h1>
<%= form_with model: Current.user, url: settings_password_path do |form| %>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feedback from reddit: https://old.reddit.com/r/rails/comments/1lmo4ud/learning_to_learn_rails_the_rails_secret_handshake/

I kind of agree that Current.user needs more explanation. I think its setup by the authentication generator in the Getting Started guide, but neither Getting Started nor this guide really explain what it is/how it works.

Adding Sign Up
--------------

We've already used the Rails authentication generator to allow users to login to their accounts. The generator created a `User` model with `email_address:string` and `password_digest:string` columns in the database. It also added `has_secure_password` to the `User` model which handles passwords and confirmations. This takes care of most of what we need to add sign up to our application.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about a link to /getting_started#adding-authentication here so that someone can quickly jump back to that section for context?

<%= link_to "Back to all users", settings_users_path %>
<h1><%= @user.full_name %></h1>
<%= tag.p @user.email_address %>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the only usage of tag.<tag> in this guide, it may be worth replacing with <p> just to not introduce another concept?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like tag.p, it's a nice way to introduce that concept IMO

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels unnecessary complexity at this point. The plain erb html would serve this well. I wonder if this preparing for something in a future tutorial.

@AmandaPerino
Copy link
Contributor

@AmandaPerino That looks great! If these tutorials are part of https://github.com/rails/website would it make sense to move this PR there as well?

But the guides are all in rails/rails, right?

As long as we merge both at the same time, it should be okay to keep them in their respective repos, unless I'm overlooking something.

Or did you mean moving all tutorials to /website?

normalizes :email_address, with: ->(e) { e.strip.downcase }
validates :first_name, :last_name, presence: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would worth mention here that has_secure_password only validates the presence of the password, but not the minimum length or complexity.

@p8
Copy link
Member

p8 commented Jun 30, 2025

@AmandaPerino That looks great! If these tutorials are part of https://github.com/rails/website would it make sense to move this PR there as well?

Or did you mean moving all tutorials to /website?

Yes, I think we should move these to /website.

It's easier to keep the website and tutorials in sync if they are in the same repo.
For example, new guides will only be published when a new version of Rails is released (major or minor). If we add tutorials to /website they get published right away after merging.

If a lot of tutorials get added to the guides (without making them part of the guides), the guides get more difficult to maintain. There will just be more text to maintain and fixes would need to get backported.

I would also expect navigation for tutorials to be slightly different than for guides?


```ruby
namespace :settings do
resource :password, only: [:show, :update]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using edit instead of show? Actually, we will be editing the password, not showing it.


```ruby#2
namespace :settings do
resource :account, only: [ :show, :destroy ]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about calling this user? Usually, in Rails an account groups many users, and even so, the controller doesn't do account.destroy, it does user.destroy.

before_action -> { redirect_to root_path if authenticated? }, **options
end
def admin_access_only(**options)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a bit out of place to me. This is an action more typical of an authorization concept, not so much authentication. Maybe move it somewhere else? Maybe an Authorization concern that has a require_admin as a class method.

@AmandaPerino
Copy link
Contributor

It's easier to keep the website and tutorials in sync if they are in the same repo. For example, new guides will only be published when a new version of Rails is released (major or minor). If we add tutorials to /website they get published right away after merging.

If a lot of tutorials get added to the guides (without making them part of the guides), the guides get more difficult to maintain. There will just be more text to maintain and fixes would need to get backported.

I would also expect navigation for tutorials to be slightly different than for guides?

That makes sense to me for the new tutorials, but a little less clear how that would work with the Getting Started guide.

It feels like the GS guide should stay in the guides.ror.org subdomain. But I'm open to differing thoughts here- is there any valid reason stopping it from also moving to /tutorials?

If it stays on the subdomain, the navigation from that tutorial to the others feels less clean.

Copy link

@GithinjiV GithinjiV left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job @excid3! Thank you for your continous contribution to the rails community!

Co-authored-by: Hartley McGuire <skipkayhil@gmail.com>
Co-authored-by: Matheus Richard <matheusrichardt@gmail.com>
@p8
Copy link
Member

p8 commented Jul 1, 2025

That makes sense to me for the new tutorials, but a little less clear how that would work with the Getting Started guide.

It feels like the GS guide should stay in the guides.ror.org subdomain. But I'm open to differing thoughts here- is there any valid reason stopping it from also moving to /tutorials?

If it stays on the subdomain, the navigation from that tutorial to the others feels less clean.

I can't imagine someone reading the "Getting Started" guide from Rails version 6.0.

The use case for the "Getting Started" guide is a bit different than other guides. Most would probably read it once to build an app and never look at it again, whereas the other guides are used to look up things more often.

The guides for older Rails version are useful when you are working on an application with that same version.
This doesn't apply that much to the "Getting Started" guide. If you install Rails for the first time you get the latest version, so for the "Getting Started" guide we probably only want to show the latest version (which helps when it's on /website instead of /rails).

So maybe it's a good idea to move that guide to /website as well?

There are some existing guides which are more tutorial like. For example the plugins guide: https://guides.rubyonrails.org/plugins.html. I'm not sure those should be moved as well.

Co-authored-by: Kyoungwon Lee (Stark) <kyoungwon.lee86@gmail.com>
Copy link

@NotGrm NotGrm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a really great guide! Despite using Rails for years, I learned a few interesting things.

What do you think about inserting tests throughout the guide, after introducing new requirements and before showing code blocks? This could help foster a TDD/test-first culture among readers.

end
```

This test is should be invalid because the user's name is missing. Since this request is invalid, we need to assert the response is a 422 Unprocessable Entity. We can also assert that there is no difference in the `User.count` to ensure no User was created.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This test is should be invalid because the user's name is missing. Since this request is invalid, we need to assert the response is a 422 Unprocessable Entity. We can also assert that there is no difference in the `User.count` to ensure no User was created.
This test should be invalid because the user's name is missing. Since this request is invalid, we need to assert the response is a 422 Unprocessable Entity. We can also assert that there is no difference in the `User.count` to ensure no User was created.

@MichaelGame-Dev
Copy link

MichaelGame-Dev commented Jul 10, 2025

@AmandaPerino amazing! For anyone reviewing and wants to preview the results:

  1. Find the latest build preview in the GH action:
image 2. Add `/guides/sign_up_and_settings.html` to the end of that URL

@MatheusRich I am trying to do just that,
Adding /guides/sign_up_and_settings.html to the end after clicking on buildkite link just ends up with a page that doesn't exist. New to Rails and the more complex stuff in Github. So can't seem to figure out how to get the latest version of the guide to look through.

@MatheusRich
Copy link
Contributor

@MichaelGame-Dev the page has changed a little since i've last saw this, but you can find the docs link in the Annotations section:

image

Click on Guides and add /guides/sign_up_and_settings.html as the path. The current link would be https://2d4dd8e7.rails-docs-preview.pages.dev/guides/sign_up_and_settings.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs rails foundation Rails Foundation PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.