我正在为一个类创建一个网站,我正在尝试使用名为"Users"的模型和一个名为"Relationships"的连接模型来实现一个朋友请求函数.我在用户#show页面上有一个按钮,它应该通过在Relationships控制器中使用create方法添加朋友.这是按钮的代码:
<%= link_to "Add as Friend", relationships_path(:friend_id => @user), method: :post %>
Run Code Online (Sandbox Code Playgroud)
但是,当我按下链接时,它会尝试访问索引方法.在查看控制台后,看起来链接正在发送GET请求,该请求路由到索引方法,而不是路由到create方法的POST请求.有人可以解释为什么会出现这种错误以及我如何解决它?
编辑:根据要求,这是我的路线中的内容:
Rails.application.routes.draw do
resources :interests
get 'interests/create'
get 'interests/destroy'
get 'home/index'
get 'sessions/create'
get 'sessions/destroy'
resources :users
resources :relationships
resources :subscriptions
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
# You can have the root of your site routed with "root"
# root 'welcome#index'
root 'home#index'
get "/auth/:provider/callback" => "sessions#create" …
Run Code Online (Sandbox Code Playgroud)