I have two callback functions side by side, and they seem to execute the exact same thing. However, the first one works, and the second one doesn't - it doesn't even execute the javascript, though the file IS rendered.
Here's the function that does not work - in a partial:
<%= button_to 'Delete', todo_path(@item.id, :format => :js, ),
:method => :delete,
:remote => true,
:form => { "data-type" => "js" },
:form_class => "btn btn-danger btn-xs" %>
In the controller:
def destroy
@item_id = params[:id]
if item = Item.find_by_id(@item_id)
item.destroy
end
respond_to do |format|
format.js {}
end
end
On the callback (in todos/destroy.js.erb):
alert("foobaz");
console.log("baz-foo");
$("#item_<%= @item_id %>").remove();
The method and the partial are rendered, but the javascript does not execute (no alert, no console log, and no delete of the item):
Started DELETE "/todos/73.js" for ::1 at 2015-04-20 20:24:37 -0700
Processing by TodosController#destroy as JS
Parameters: {"authenticity_token"=>"sKfPWYP4owepOSDKBtTAoUMN4cVez/d5rz7k+UV0BY9Eu3Qkv/loiSpg4E6hN8Jmqih0+1v0WUROjL8h8IBnyQ==", "id"=>"73"}
Item Load (4.5ms) SELECT `items`.* FROM `items` WHERE `items`.`id` = 73 LIMIT 1
Rendered todos/destroy.js.erb (0.4ms)
Thoughts?
UPDATE
I just added some Ruby debugging in:
<% print "HERE I AM" %>
And it printed out. So the template is being rendered, and it's just the javascript is not being called. Still not a solution :(
Additionally, in every way I can tell, it looks just like the other function, other than it's being rendered in a partial.