High Leverage Rails
Introduction
Introduction to this course
Why use Ruby on Rails
Why use SQLite
Ruby on Rails + SQLite
Powering Your App with SQLite
Creating tables
Timestamps
Column types
Typeof
Ruby types
Creating table introduction
Creating table advanced
Inserting data
Updating data
Upserting data
Reading data
Virtual columns
Enums
Introduction to JSON
Indexing JSON
JSON table functions
Building a Modern Rails Application
Creating a new Rails application
Installing Solid Queue
Installing Solid Cache
Installing Solid Cable
Dockerfile
Application overview
Authentication
Base styles
Registration
Scaffolding posts
Polishing posts
Scaffolding comments
Polishing comments
Polishing models
Polishing controllers
Creating new post
Updating post
Reviewing MVP
Tagging posts
Custom tags
Friendly URLs
Full text search
Deploying & Operating Your App
Backups
Check Litestream locally
Verifying backups
Deployment options
Deploying with Hatchbox
Deployment constraints
Vertical scaling
Database access
Migrations
Locked video

Please purchase the course to watch this video.

Video thumbnail
Building a Modern Rails Application
Registration

Full Course

$
129
$179
USD, one-time fee
This course came at the perfect time. I’ve recently gotten back into Rails after an 18-year hiatus, and this was a perfect refresher and shows just how much you can accomplish with Rails right out of the box.
Garrett Winder
Garrett Winder

Move fast and fix things

Application monitoring that helps developers get it done.

Rails hosting made simple

Deploy apps to servers that you own and control.

Summary

Learn how to implement user signup in a Rails application using scaffold generators. In this video, I create user routes, controllers, and views, enhance the UI with Tailwind CSS, and ensure seamless authentication by automatically signing in new users. With signup complete, we’re ready to build the post submission feature for Lorem News.

Video Transcript

Now that we have our base styles prepared and our authentication system in place, we can focus on allowing users to sign up for our application. To do this, we'll use the scaffold generators that Rails provides.

Let's jump into our application and examine the command we need to run. We will scaffold the user resource with an email address and a password. However, since the authentication generator has already created this model and migration, we need to skip the collision check. This ensures that if any files already exist, Rails will skip them instead of raising conflicts.

Generating the User Resource

Running the command, we see that Rails:

  • Skips creating the migration and model (since they already exist)
  • Adds a resource route
  • Generates a user controller
  • Creates all RESTful views
  • Includes test helpers

Now, let's review our user controller. It follows the standard RESTful pattern, including:

  • index, show, new, and edit for GET requests
  • create, update, and destroy

We'll use this setup to allow users to sign up. The new action will render the signup form, which submits to create. Once a user successfully signs up, they will be redirected to the show page.

Since signup happens before authentication, we need to explicitly allow unauthenticated access for new and create. This mirrors what we did in the sessions controller for login functionality.

Before making further modifications, let's commit our changes.

Navigating to /users/new, we see the default signup form. The base styles are working well, but a few improvements are needed:

  • Add spacing between form elements for better readability
  • Remove the back link since users should proceed to sign in instead of navigating back
  • Remove the index action (there's no need to display a list of users in this app)

Improving the Signup Form

To streamline the user experience, we'll:

  1. Remove the index action from the controller, view, and routes
  2. Adjust form styling for better readability
  3. Ensure input fields use full width

Jumping into the controller, we delete the index action and remove the corresponding view and route. Next, in our Tailwind CSS file, we define new form styles.

Now, form elements have better spacing. However, the input fields are not full-width. Investigating the issue, we see that styles were only applied to direct children of forms. To fix this, we extend styles to descendants instead of only direct children.

Now our form looks clean and structured.

Finalizing User Signup Flow

At this point, the signup form functions correctly, but:

  • Users are not automatically signed in after signing up
  • The success message could be clearer

To fix this, we update the users controller:

def create
  @user = User.new(user_params)

  if @user.save
	start_new_session_for @user
	redirect_to @user, notice: "Welcome! You are now signed up."
  else
	render :new, status: :unprocessable_entity
  end
end

Now, after signing up, users are:

  • Automatically logged in
  • Redirected to their profile page
  • Presented with a clear success message

Testing the changes, everything works seamlessly. The last step is to remove any remaining references to the index action and improve flash message styling, which we can refine later.

With signup fully implemented, let's commit our changes.

Now, we can move forward and focus on building the post submission feature for our Lorem News application.