Reputation: 1974
I have problem with action in my controller - when I call link_to in view with destroy action there is an error:
ActionController::UrlGenerationError
No route matches {:controller=>"user_votes", :action=>"destroy", :recipient_uid=>2911238}
routes:
App::Application.routes.draw do
devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
resources :users
resources :votes
resources :user_votes
root 'main#home'
end
user_vote_controller:
class UserVotesController < ApplicationController
def destroy
@user_vote = UserVote.find_by(params[:recipient_uid])
@user_vote.destroy
redirect_to root_url
end
end
view file:
= link_to 'Delete', {controller: "user_votes", action: "destroy", recipient_uid: friend.uid}, method: "delete"
Can you show me where I made a mistake?
Thanks!
Upvotes: 0
Views: 585
Reputation: 364
The resource url for the destroy function is actually 'user_votes/:id'. So you need to pass in the :id
parameter when you call the link_to helper
= link_to 'Delete', {controller: "user_votes", action: "destroy", recipient_uid: friend.uid, id: some_id}, method: "delete"
Replace some_id
with the actual resource id.
Upvotes: 1