我undefined local variable or method
在视图文件夹中收到此错误 toggle_follow_path'`。我可能对方法有问题,或者使用 off form_tag + toggle_follow_path 任何帮助都将受到欢迎,谢谢。顺便说一下,切换关注的目标是关注或取消关注某个人。
在路由文件中
match '/:username/toggle_follow', to: 'home#toggle_follow'
家庭控制器
def toggle_follow
@user = User.find_by_username(params[:username])
if current_user.is_friend? @user
flash[:notice] = "You are no longer following @#{@user.username}"
current_user.remove_friend(@user)
else
flash[:notice] = "You are now following @#{@user.username}"
current_user.add_friend(@user)
end
redirect_to user_flits_path(@user)
end
看法
<h1><%= image_tag @user.gravatar_url, :align => "top" %> <%= @user.username %></h1>
<%= form_tag toggle_follow_path, :method => :post do %>
<% if current_user.is_friend? @user %>
<%=h submit_tag "Following" , :class => "button" %>
<% else %>
<%=h submit_tag "Follow" , :class => "button" %>
<% end %>
<% end %>
<%=h render :partial => "flits_list", :locals => {:flits => @flits }%>