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?&¤t_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%>
<% = link_to'Unfollow', community_follows_path (community), method:: delete%>
The method part of link_to must be selected from four http methods.
Answer # 2
@follow looks empty ...
Answer # 3
@follow = current_user.follows.find_by (community_id :: @community_id)
@follow = current_user.follows.find_by (community_id :: @ community.id)
Isn't it a mistake?
In any case, in the code written
I don't think it is defined anywhere.
How is it?
- ruby on rails 6 - [error] nomethoderror in followscontroller # create undefined method `follows' for nil: nilclass
- ruby on rails - nomethoderror in itemscontroller # new error
- ruby on rails 6 - [error] nomethoderror in communitiescontroller # create undefined method `published?'for # <community: 0x0
- ruby on rails 6 - [error] nomethoderror in communities # index undefined method `following?'for nil: nilclass
- ruby on rails - i don't understand the content of the error
- ruby on rails 6 - [error] uninitialized constant user (call'userconnection' to establish a connection) :: image
- ruby on rails - rails routing error
- ruby on rails - i get an error without being created
- ruby on rails 6 - when i press new user registration, i get an error of no route matches [get] "/ users"
- ruby on rails - error when implementing rails6 follow function
- ruby on rails - syntax error cannot be resolved
- ruby - [rails] about the error that occurs when deleting likes (routing error)
- ruby on rails 5 - i want to get an error message when i enter the user id in full-width in url
- ruby on rails - i want to resolve rails name error
- ruby - an error occurs when building a rails 6 environment with docker
- ruby on rails 6 - i want to solve the error that occurred while implementing the product listing function
- error in building environment of ruby on rails
- ruby on rails - i get a template is missing error in render
- ruby on rails - rspec validation error
- python - you may need to restart the kernel to use updated packages error
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- dart - flutter: the instance member'stars' can't be accessed in an initializer error
- [php] i want to get account information using coincheck api
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- sh - 'apt-get' is not recognized as an internal or external command, operable program or batch file
- i want to call a child component method from a parent in vuejs
- i want to check the type of a shell script variable