我得到這個錯誤undefined local variable or method
toggle_follow_path'`在視圖文件夾中。我可能有錯誤的方法或使用關閉form_tag + toggle_follow_path任何幫助將受到歡迎謝謝。順便說一下,切換跟隨的目標是遵循或不遵循某一個。未定義的局部變量或方法`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 }%>
謝謝你,它的工作 – skip87