1

Below I have the link-helpers for the actions edit and destroy. The first link (and all the others) is working perfectly but the second creates a weird url that doesn't work.

<%= link_to "Edit", edit_event_path(organizer_vanity_url: event.organizer.vanity_url, id: event.id) %>  
<%= link_to 'Remove', event_path(organizer_vanity_url: event.organizer.vanity_url, id: event.id), method: :delete, data: { confirm: 'Are you sure?' } %>

This is from the routes.rb:

scope "organizer" do
  scope ":organizer_vanity_url" do
    scope "manage" do
      resources :events
    end
  end
end

What is the difference between the delete link-helper and the others (as that's the only one that doesn't work)?

Fellow Stranger
  • 32,129
  • 35
  • 168
  • 232

1 Answers1

0

link_to - is GET-request-like helper (by default)

DELETE method is POST-like method

so, you passing post method to get helper and receive "weird url"

to solve this you have two options:

  • use button_to instead of link_to helper (first one is for post form submitting, by default)

  • use js to correctly handle your link.

Community
  • 1
  • 1
okliv
  • 3,909
  • 30
  • 47