RoR 웹 사이트 내에서 우정을 맺고 있습니다. 모델은 user_id, friend_id 및 pending (boolean)입니다. 우정에 관한 RailsCast를 대부분 따라 갔지만 약간 변경했습니다. 내가 지금까지 가지고하면 사용자의 페이지로 이동 할 때 요청 우정을 클릭 할 수 있으며 코드를 사용ruby on rail 작업 경로와 일치하는 경로가 없습니다.
이user_friendships_path(current_user, :friend_id => @user), :method => :post
이것은이 우정 컨트롤러 방법을 만들 호출합니다. 보류 중을 true로 자동 설정합니다. 내가 지금 원하는 것은 받아들이 기위한 링크를 가지고있는 것입니다. 그래서 난 그냥 false로 그 부울을 설정해야하기 때문에, 실제로 편집 페이지로 이동하지 않으
(<%= link_to "Accept", user_friendship_path(:user_id => current_user.id, :friend_id => friendship.user.id, :pending => 'false'), :method => :put %>)
처럼 설정하려고, 그래서 나는 직접 업데이트를 호출합니다. 그러나이 페이지를 실행하면 다음과 같은 오류가 발생합니다.
No route matches {:action=>"destroy", :controller=>"friendships", :user_id=>1, :friend_id=>2, :pending=>"false"}
이유를 모르겠습니다. 나는 destroy (with : method => : delete)를 호출하지 않으며, 실제로 Friendship 컨트롤러 내에 destroy 메소드가있다.
자원이처럼 설정됩니다
resources :users do
resources :friendships
end
그리고 "레이크 경로"를 실행 한 경로는 다음과 같습니다
user_friendships GET /users/:user_id/friendships(.:format) {:action=>"index", :controller=>"friendships"}
user_friendships POST /users/:user_id/friendships(.:format) {:action=>"create", :controller=>"friendships"}
new_user_friendship GET /users/:user_id/friendships/new(.:format) {:action=>"new", :controller=>"friendships"}
edit_user_friendship GET /users/:user_id/friendships/:id/edit(.:format) {:action=>"edit", :controller=>"friendships"}
user_friendship GET /users/:user_id/friendships/:id(.:format) {:action=>"show", :controller=>"friendships"}
user_friendship PUT /users/:user_id/friendships/:id(.:format) {:action=>"update", :controller=>"friendships"}
user_friendship DELETE /users/:user_id/friendships/:id(.:format) {:action=>"destroy", :controller=>"friendships"}
어떤 도움을 주시면 감사하겠습니다. 자세한 정보가 필요하면 알려주십시오.
감사합니다.
link_to "수락", user_friendship_path (: user_id => current_user.id, : friend_id => friendship.user.id), : 방법 :> : put %>)을 시도해보십시오. 실제로 보류중인 매개 변수를 보내지 않아도됩니다. – apneadiving