From the course: Hands-On Introduction: Ruby on Rails
Unlock the full course today
Join today to access over 24,600 courses taught by industry experts.
Using Turbo Streams to show the created post - Ruby on Rails Tutorial
From the course: Hands-On Introduction: Ruby on Rails
Using Turbo Streams to show the created post
- [Instructor] Before starting, Turbo Streams will act on the front-end with JavaScript. You must adapt the flash messages first. Open the index template and cut the p tag from the notice. Now create a new partial inside the layouts folder called notice. Paste the p tag, delete the ID because it's not necessary here. Go back to the index template, and inside the if block, create a div with ID notice. And inside, render the partial we just created. Moving the notice message to a partial will allow us to call it from the front-end when necessary. To make the post creation work, you have to make some modifications to the controller. Open the posts controller and look for the create action. If the post is saved correctly, add a new format, turbo_stream. The only thing to put here is the flash message that will happen now. This is important because the page won't reload, it'll be a notice. And the message is "Post was successfully created." Now we need to tell Turbo where to place the new…