I installed the follow button before, I don't remember where I installed it before The place is pretty confusing It was a place that I wouldn't normally use there, so I will move it to a place that is easier to understand and use.
The destination is here. Next to current_user.name for each post.
First, let's go find the follow button that we made somewhere before.
I found it! !!
ruby:app/views/users/show.html.haml
.users-show
= render 'follow_form'
= render 'stats'
I'm calling it with this partial template.
Where are you calling from here?
ruby:app/views/users/_follow_form.html.haml
- unless current_user?(@user)
- if current_user.following?(@user)
= render 'unfollow'
- else
= render 'follow'
This is also called with a partial template.
Where are you calling from here?
ruby:app/views/users/_unfollow.html.haml
= 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"
ruby:app/views/users/_unfollow.html.haml
= 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 let's just paste this into the destination.
= render 'follow_form'
When I pasted it, I got this error.
ActionView::MissingTemplate in Posts#index
I was told that there was a problem with posts # index.
Wait a minute.
The file you are trying to call app/views/users/_follow_form.html.haml
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, no error appears, but it is not displayed. .. .. why? ??
posts_controller.rb
def index
@posts = Post.all.includes(:user).order("created_at DESC").page(params[:page]).per(5)
@post = Post.new
@user = current_user
end
It looks like this was bad yesterday. The bad thing about this is that all @users become current_user. Now, no matter which user's link is clicked, it goes to the current_user's My Page and does not go to that person's My Page.
@user =The person who posted the post
I have to write.
When I looked at Twitter, there was no follow button on the list screen. The follow button wasn't on the list screen, only after I went to the user's details screen. So don't put a follow button on the list screen.
Recommended Posts