目前,在为一位用户显示关注/取消关注按钮时,我拥有完整的功能。我能够正确关注和取消关注任何用户。
但是,当显示所有用户的列表并在每个用户上显示关注/取消关注按钮时。
当我点击关注时,我得到了。
我在 _unfollow.html.erb 的第二行为 #<#:0x007fa8a9b4f448> 得到未定义的局部变量或方法“following” -完整错误请参见下图
我在渲染部分时传入了变量。
<%= render 'follow_aud_form', :following => following if signed_in? %>
我还可以检查“以下”并查看实例数据。
当我返回点击后,它实际上跟随/取消关注选定的用户,但是它首先生成错误
请参阅下面的代码
users_controller
def following
@title = "Following"
@user = User.find(params[:id])
@users = @user.followed_users
render 'show_follow'
end
def followers
@title = "Followers"
@user = User.find(params[:id])
@users = @user.followers
render 'show_follow'
end
show_follow.html.erb
<% @users.each do |following|%>
<div class="span1">
<%= render 'follow_aud_form', :following => following if signed_in? %>
</div>
<% end %>
follow_aud_form
<div id="follow_form">
<% if current_user.following?(following) %>
<%= render 'unfollow', :following => following %>
<% else %>
<%= render 'follow', :following => following %>
<% end %>
</div>
_follow_html
|__<%= @gaza_id = following.id %>__|
<%= form_for(current_user.relationships.build(followed_id: @gaza_id)) do |f| %>
<div><%= f.hidden_field :followed_id %></div>
<%= f.submit "Follow",:type => :image, :src => "/assets/follow.png" %>
<% end %>
_unfollow.html
|__<%= @slim_id = following.id %>__|
<%= form_for(current_user.relationships.find_by_followed_id(@slim_id),
html: { method: :delete }) do |f| %>
<%#= f.submit "Unfollow", class: "btn btn-large" %>
<%= f.submit "Unfollow",:type => :image, :src => "/assets/following.png" %>
<% end %>