Ruby on rails 未定义的局部变量或方法“toggle”follow\u path';

Ruby on rails 未定义的局部变量或方法“toggle”follow\u path';,ruby-on-rails,ruby-on-rails-3,routes,Ruby On Rails,Ruby On Rails 3,Routes,我在视图文件夹中遇到此错误未定义的局部变量或方法toggle_follow_path'`可能是该方法或使用off form_tag+toggle_follow_path时出错。欢迎提供帮助。谢谢。顺便说一下,切换跟随的目标是跟随或取消跟随某个对象 路由文件中的 match '/:username/toggle_follow', to: 'home#toggle_follow' 家庭控制器 def toggle_follow @user = User.find_by_u

我在视图文件夹中遇到此错误
未定义的局部变量或方法
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 }%>
“top”%%>
:post do%>
“按钮”%>
“按钮”%>
“flits_list”,:locals=>{:flits=>@flits}%>

使用
:作为
匹配的
选项指定所需帮助者的姓名:

match '/:username/toggle_follow', to: 'home#toggle_follow', as: 'toggle_follow'

这样将创建
切换跟随路径
切换跟随url

它需要接受
:username
参数

试试这个:

toggle_follow_path(:username => "johndoe") # fill in the correct username.

但是在控制器中使用@user find by username并不意味着我不必在路径上指定它,顺便提一下,这是个问题