[Ruby] [Personal application work memo] Move the location of the follow button

1 minute read

The follow button was installed before, I don’t remember where I installed it before, The place is quite difficult to understand, Since it was a place that I would not normally use if there, I decided to move it to a place that is easier to understand and use.

The destination is here. Screenshot 2020-08-25 PM 7.28.35.png Next to current_user.name for each post.

First of all, let’s go find the follow button I made somewhere before.

I found it! !!


  = render'follow_form'
  = render'stats'

I’m calling this part template.

Where are you calling from?


- unless current_user?(@user)
  -if current_user.following?(@user)
    = render'unfollow'
    = render'follow'

This is also called by a partial template.

Where are you calling from?


= form_for(current_user.following_relationships.build(following_id: @user.id)) do |f|
  = f.hidden_field :following_id
  = f.submit "Follow", class: "btn btn-large btn-primary follow-btn"


= form_for(current_user.following_relationships.find_by(following_id: @user.id), html: {method: :delete}) do |f|
  = f.submit "Unfollow", class: "btn btn-large btn-primary follow-btn"

I’ll definitely get an error, but I’ll just paste this to the destination for a test.

= render'follow_form'

After pasting, I got this error.

ActionView::MissingTemplate in Posts#index

I was told there was a problem with posts#index.

Wait a minute.

The file you are trying to call app/views/users/_follow_form.html.haml

Who to call app/views/posts/_post.html.haml

If the directory is different, you have to write it like that.

= render'users/follow_form'

When I put it in this, I get no error, but it is not displayed. .. .. why? ?

Before this is resolved, another discovery will be made. I finally found the follow button. It also works fine. If you press the follow button, you can follow properly, It works as a follow button. All we have to do is move the location of this.


 def index
    @posts = Post.all.includes(:user).order("created_at DESC").page(params[:page]).per(5)
    @post = Post.new
    @user = current_user

This seems to be bad yesterday. The bad thing about this is that all @users become current_users. Now, no matter which user’s link is clicked, it will go to the current_user’s My Page and not to that person’s My Page.

@user = the person who posted the post

I have to write

After all, I decided to stop adding the follow button to the list screen

When I saw Twitter, there was no follow button on the list screen. The follow button wasn’t on the list screen, but after going to the user details screen. Therefore, stop adding the follow button to the list screen.

Tags: ,