Chapter 14 of the Rails Tutorial has some themes to extend your functionality for those who have completed the Tutorial. I am challenging the reply function, which is the first theme. I'm still working on it, but I'll post it as far as I can.
The requirements are written as follows.
Twitter has the ability to reply to a user by entering the user's login name after the @ symbol while typing in the micropost. This post is only visible to the recipient's feed and to the people who follow you. Let's implement a simple version of this reply feature. Specifically, @reply should only appear in the recipient's feed and the sender's feed.
Specifications hints are also written.
To implement this, I think I need to add an in_reply_to column in the microposts table and an additional including_replies scope to the Micropost model.
Break down your requirements specifically.
・ @Reply is displayed by the following three parties Recipient of reply Reply sender (self) Reply sender followers
Not visible to users other than the above
-When "@reply user's login name" is entered at the beginning of the micropost, this post is judged as reply.
When I read back "6.2.5 Uniqueness of email address" in Tutorial, it was written whether to distinguish between uppercase and lowercase letters. Should the username be case-sensitive, or whether Taro and TARO should be different. Find out how twitter is on the net.
Although it is the same internally, there were many articles that it was divided at the time of input. I couldn't find the article I was writing. I will make it with the same specifications as the email address.
I decided to add this case feature later rather than from the beginning. It seemed easy to add later.
It's similar to the features we added earlier, so read back which features are similar.
Similar to the function of the micropost in Chapter 13 Similar to the user registration function in Chapter 6.7 6.2.5 Verify uniqueness Uniqueness of email address
Based on the result, we considered the following functions.
-Added a function to model that can judge whether to display or not with reply. Whether this post is reply -Added the function to determine the input of @reply to view or controller -Added to model and view so that the user name is unique
I decided to add the last "username unique" feature later rather than from the beginning. This is because I thought that I should first create something that works only with unique test data, and then add a constraint function that makes it unique later.
Reread Chapter 14, 14.1.1. It was a relative in between ids.
I think I need to add an in_reply_to column in the microposts table and an additional including_replies scope to the Micropost model.
Think about how to change the model with the hint.
What would the type be if we added a column for in_reply_to? I thought it was an integer, the same as id, because it identifies which user it is.
Whether to add a micropost method or modify an existing method. Refer to Table 13.1 user.micrposts Existing changes that replace a set of User microposts user.microposts.build (arg) Existing modification that returns a new Micropost object associated with user user.microposts.find_by (id: 1) Existing modification to search for microposts that are tied to user and have id 1.
Think about adding a reply method. user.microposts.create (arg, reply: user2) Create a reply micropost to user2 We decide to modify the existing create method.
There are two main screens, one for entering a reply and the other for displaying a reply.
I thought that I didn't need to increase the number of input items, because I put @reply at the beginning of content.
Do you need a reply-only screen for output? Check Twitter. If you click the original Tweet, the reply will move to another screen and the list of replies will be displayed. A list of parent-child Tweets of reply is displayed.
It's a bit complicated, so I won't go that far this time, and I'll display it on the same screen as the original Tweet.
The image on the screen is just text, as it's a hassle to mock. comment box : @reply michael Cum aspermatur ..
Display image of Feed @reply michael Cum aspermatur ..
If the user_id is not found, the friendly design will display an error as you type. I'll show the error because it should be checked when creating.
What to do if the user_id is deleted after posting? Should I delete this micropost? I think it's better to leave only the micropost that was replied to someone who is no longer there, and I don't think that the micropost will be deleted.
3.0 hours from 9/27 to 10/1.