How can I create delete link_to in Rails app?
Votes controller
class VotesController < ApplicationController
def destroy
@user = User.find(params[:id])
@user.votes.pluck(:author_uid).delete(current_user.uid)
end
end
Routes
votes_path GET /votes(.:format) votes#index
POST /votes(.:format) votes#create
new_vote_path GET /votes/new(.:format) votes#new
edit_vote_path GET /votes/:id/edit(.:format) votes#edit
vote_path GET /votes/:id(.:format) votes#show
PATCH /votes/:id(.:format) votes#update
PUT /votes/:id(.:format) votes#update
DELETE /votes/:id(.:format) votes#destroy
What should I write in link_to in view?
I tried
= link_to 'Delete vote', {controller: "votes", action: "destroy"}, method: "delete"
and
= link_to 'Delete vote', vote_path(vote), method: :delete
users/index.html.haml
- @vk.friends.get(uid: current_user.uid, fields: fields) do |friend|
%td.span
.centred
.image
.circled
= image_tag friend.photo_medium
%span= friend.uid
%span= link_to "#{friend.first_name} #{friend.last_name}", "http://vk.com/id#{friend.uid}", target: "_blank"
%span= define_age(friend) == '' ? define_sex(friend) : define_sex(friend) + ', ' + define_age(friend)
- if current_user.user_votes.pluck(:recipient_uid).include?(friend.uid)
= link_to('Delete',{controller: :votes, id: vote.id, action: :destroy}, confirm: "Are you sure you want to delete ?", method: :delete)
- else
= link_to 'Vote', {controller: "votes", action: "create", uid: friend.uid}, method: "post", confirm: "You sure", class: 'button medium pink'
Of course it's not working. I'm sure I should fix it with routes, but I don't know how.
Please comment, if you need more information.
Thanks!