I follow the railstutorial.ru tutorial. I do everything as it is written but one error appeared, the follow button works and the unfollow button does not.

Here is the code.


sample_app / app / views / users / _unfollow.html.erb

<%= form_for(current_user.relationships.find_by(followed_id: @user), html: { method: :delete }, remote: true) do |f| %> <%= f.submit "Unfollow", class: "btn btn-large" %> <% end %> 

sample_app / app / views / users / _follow.html.erb

 <%= form_for(current_user.relationships.build(followed_id: @user.id), remote: true) do |f| %> <div><%= f.hidden_field :followed_id %></div> <%= f.submit "Follow", class: "btn btn-large btn-primary" %> <% end %> 

sample_app / app / controllers / relationships.rb

 class RelationshipsController < ApplicationController before_action :signed_in_user def create @user = User.find(params[:relationship][:followed_id]) current_user.follow!(@user) respond_to do |format| format.html { redirect_to @user } format.js end end def destroy @user = Relationship.find(params[:id]).followed current_user.unfollow!(@user) respond_to do |format| format.html { redirect_to @user } format.js end end end 

sample_app / app / views / relationships / create.js.erb

 $("#follow_form").html("<%= escape_javascript(render('users/unfollow')) %>") $("#followers").html('<%= @user.followers.count %>') 

sample_app / app / views / relationships / destroy.js.erb

 $("#follow_form").html("<%= escape_javascript(render('users/follow')) %>") $("#followers").html('<%= @user.followers.count %>') 


PS Here is a tutorial railstutorial.org

PPS Chapter 11.2.5



Closed due to the fact that off-topic participants D-side , Grundy , cheops , zRrr , aleksandr barakin Jul 2 '16 at 0:17 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - D-side, Grundy, cheops, zRrr, aleksandr barakin
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • one
    In the browser console with any errors are displayed? In server logs? - D-side
  • @ D-side There are no errors in the browser console, I work in a virtual machine, through localhost: 3000, where are the logs? - Nikita
  • Where rails server / rails s launched from. - D-side
  • @ D-side There was a mistake in the logs (I didn’t think of looking) - Nikita
  • @ D-side in user.rb was a function undollow and not unfollow thanks for the help and time - Nikita

0