Home>

Since we are creating a follow function, we are trying to display the'follow'and'unfollow' buttons with if statements.
However, even though I was able to follow, an error was displayed as soon as I pressed the unfollow button.
By the way, it's not asynchronous.
I'm still not good at verbalizing the assignment, but I would appreciate your help.

class FollowsController</pre>
<p><br />
<index.html.erb></p>
<pre><code>
    
    <% @ communities.each do | community |%>
         
          <% = link_to community_path (community) do%>
               
                  
                  <% = attachment_image_tag community,: intro_image, fallback: "no-image.jpg", class: "rounded-top"%>
                  
                  
                  <% = community.title%>
                  
                <% if current_user.present?&&current_user.following? (Community)%>
                  <% = link_to'Unfollow', community_follows_path (community), method:: destroy%>
                <% else%>
                  <% = link_to'follow', community_follows_path (community), method:: post%>
                <% end%>
                <% = community.follows.count%>
               
          <% end%>
          
     <% end%>
    


Rails.application.routes.draw do

  devise_for: users
  # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
  root to: "communities # index"
  resources: users
  resources: communities do
    resource: follows, only: [: create,: destroy]
  end

  resources: mypage, only: [: profile] do
    member do
      get'profile'
      get'posted_community'
      get'followed_community'
    end
  end
end
  • Answer # 1

    <% = link_to'Unfollow', community_follows_path (community), method:: destroy%>
    Not correctly
    <% = link_to'Unfollow', community_follows_path (community), method:: delete%>
    was.
    The method part of link_to must be selected from four http methods.

  • Answer # 2

    @follow looks empty ...

  • Answer # 3

    Probably,

    @follow = current_user.follows.find_by (community_id :: @community_id)


    Is

    @follow = current_user.follows.find_by (community_id :: @ community.id)


    Isn't it a mistake?
    In any case, in the code written
    @community_id
    I don't think it is defined anywhere.

    How is it?