I am trying to send a POST request ( 'remove_tag_named' )and getting a simple OK back on success ; it doesn't work..
the post is correctly sent , but after then it's looping on sending a GET request to the same url, with the error
301 Moved Permanently
I should not be far fro the solution, but I am stuck :
In my routes.rb
namespace :administration do
resource :dashboards, :only => :show do
collection do
post :remove_tag_named
end
end
end
In my view :
= link_to t(:delete), "#", :id => :delete_tag_link
# generated html => <li><a id="delete_tag_link" href="#">remove</a></li>
my js.coffee script ( # this should be using JSONP I guess )
$('#delete_tag_link').bind "click", (e) ->
selected = $('#tags.tab-pane.active #tag-list li span.myTag.selected')
tagName = selected.html()
alert 'going remove tag: ' + tagName # checking I get the correct tag value
$.ajax
url: "/" + locale + "/administration/dashboards/remove_tag_named.json"
type: "POST"
dataType: "json"
contentType: "json"
data: {"tag_name": tagName }
success: (result) ->
selected.remove()
I have also set an init js
$.ajaxSetup beforeSend: (xhr) ->
xhr.setRequestHeader "X-CSRF-Token", $("meta[name=\"csrf-token\"]").attr("content")
and the console output :