I made a reply function for the Rails Tutorial extension (Part 1)

About extensions in Chapter 14 of the Rails Tutorial

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.

Check the requirements to make and make the specifications

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.

Deep dive into the specs, look up for reference to the illustrated twitter

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.

What kind of function to make is similar to the function added before, so read it back

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.

A model that designs functions in detail

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.

microposts

Column name attribute
id integer
content text
user_id integer
in_reply_to integer
created_at datetime
updated_at datetime

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.

Method for designing functions in detail

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.

View to design functions in detail

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 ..

View input error check to design functions in detail

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.

Time required

3.0 hours from 9/27 to 10/1.

Recommended Posts

I made a reply function for the Rails Tutorial extension (Part 1)
I made a reply function for the Rails Tutorial extension (Part 5):
I made a reply function for Rails Tutorial extension (Part 2): Change model
I made a reply function for the Rails Tutorial extension (Part 4): A function that makes the user unique
I tried to make a reply function of Rails Tutorial extension (Part 3): Corrected a misunderstanding of specifications
Rails Tutorial Extension: I created a follower notification function
I tried to make a message function of Rails Tutorial extension (Part 1): Create a model
I tried to make a message function of Rails Tutorial extension (Part 2): Create a screen to display
[Rails] I made a draft function using enum
I made a check tool for the release module
Tutorial to create a blog with Rails for beginners Part 1
Tutorial to create a blog with Rails for beginners Part 2
Tutorial to create a blog with Rails for beginners Part 0
I made a simple recommendation function.
I made a Ruby container image and moved the Lambda function
Rails Tutorial Extension: I tried to create an RSS feed function
I made a plugin for IntelliJ IDEA
I made a Diff tool for Java files
I rewrote the Rails tutorial test with RSpec
I made a Ruby extension library in C
I summarized the naming conventions for each Rails
I made a LINE bot with Rails + heroku
I made a portfolio with Ruby On Rails
I made a Docker image of SDAPS for Japanese
I changed the way Rails tutorials run: Rails Tutorial Notes-Chapter 9
I made a method to ask for Premium Friday
A note for Initializing Fields in the Java tutorial
What should I use for the testing framework [Rails]
I want to define a function in Rails Console
I made a library for displaying tutorials on Android.
I made a function to register images with API in Spring Framework. Part 1 (API edition)
I want to add a delete function to the comment function
I made a function to register images with API in Spring Framework. Part 2 (Client Edition)
I made a Japanese version of Rails / devise automatic email
I tried to introduce Bootstrap 4 to the Rails 6 app [for beginners]
I made a development environment with rails6 + docker + postgreSQL + Materialize.
[Rails] I tried using the button_to method for the first time
I want to implement a product information editing function ~ part1 ~
Rails: I've summarized the model and database for a moment.
A note about the seed function of Ruby on Rails
I tried JAX-RS and made a note of the procedure
I want to create a form to select the [Rails] category
[Rails] Implemented a pull-down search function for Active Hash data
Modeling a Digimon with DDD for the first time Part 1
I made a chat app.
Rails ~ Understanding the message function ~
I tried the Docker tutorial!
I tried the VueJS tutorial!
[Rails] Implementation of tutorial function
When I made a bar graph with MPAndroidChart, the x-axis label was misaligned for some reason
I made a SPA with Rails + Nuxt.js for half a year of self-study, so please take a look.
[Rails] I made a simple calendar mini app with customized specifications.
Implement a refined search function for multiple models without Rails5 gem.
I want to create a chat screen for the Swift chat app!
I want to add a browsing function with ruby on rails
I tried to implement the image preview function with Rails / jQuery
I recently made a js app in the rumored Dart language
I got a warning message with the rails _6.0.3_ new hello_myapp command
I made a gem to post the text of org-mode to qiita
I made a question that can be used for a technical interview
I made a method to ask for Premium Friday (Java 8 version)