Skip to content

Conversation

@bknoles
Copy link
Collaborator

@bknoles bknoles commented Nov 19, 2025

Steps

  1. If you haven't already, create a user by running through registration process.
  2. Visit /topics
  3. Click the "New Topic" button
  4. Click "Create topic" without filling out the form. Notice that errors are added to the form.
  5. Fill the form out and submit it. You will land on a topic page.

What is happening?

The create action in our TopicsController looks almost identical to an equivalent default Rails application. Inertia knows how to follow redirects, so a successful save is exactly the same. If there are errors, we need to pass the errors in the inertia option of the redirect. If we do that, the Inertia <Form /> component will have access to the Rails validation errors.

The other interesting thing in the example is that we are saving multiple models at once. We require that a user adds the first message to the topic they are creating. To accomplish this, we use nested attributes and a Rails validation context. If we always validated that a topic had at least one message, our database seeds would break. So we are treating this form as a special case, rather than the default. This doesn't have anything to do with Inertia, its... just regular ol' Rails patterns! And that's the point. Because Inertia is built with all of the helpful MVC constraints in mind, it plays really nicely with existing Rails best practices.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants