Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Rails 8 Course - Beginner to Intermediate!
You have completed Rails 8 Course - Beginner to Intermediate!
Preview
This video demonstrates how to implement a dynamic like button in a Rails application using Turbo Frames and Turbo Streams, allowing users to like and unlike posts, updating the like counter in real-time.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
In this case,
it decremented because I unliked it.
0:00
If I add it, it makes it red and
also adds one to the like counter.
0:01
So we're just gonna add this simple
like button to our application.
0:05
It works exactly the same way as Twitter.
0:08
So let's get started.
0:10
Okay, guys, the first thing that we're
going to do is run a command to generate
0:11
a resource for the likes.
0:14
So stop the server and
hit do clear, as we always do.
0:15
And in this case, we're going to run
a command called rails g resource like.
0:19
And then because it's gonna be
attached to two other models.
0:24
The first one is the user model,
because each user will have a liked post.
0:28
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up