I am struggling to troubleshoot why this ajax call on a standard Destroy method won't work. From looking at my HTML source, I think it might be a problem with either how I'm creating divs using div_for OR it has something to do with my js. I'm at a loss for troubleshooting javascript.
My view:
<% @quizzes.each do |quiz| %>
<%= div_for quiz do %>
<tr>
<td>
<%= link_to quiz.name, quiz_review_path(quiz.id) %>
</td>
<% if quiz.finished? %>
<td>
<%= link_to "Results", quiz_results_path(quiz) %>
</td>
<% elsif quiz.questions.first != nil %>
<td>
<%= link_to "Take quiz", question_answer_path(question_id: quiz.questions.first.id) %>
</td>
<% else %>
<td>
<%= link_to "Broken, delete!", nil %>
</td>
<% end %>
<td>
<%= link_to "Delete", quiz_path(quiz), method: 'delete', remote: true %>
</td>
</tr>
<% end %>
The controller:
def destroy
@quiz = Quiz.find(params[:id])
@quiz.destroy
respond_to do |format|
format.html { redirect_to quizzes_path }
format.js
end
end
My views/quizzes/destroy.js
$(document).ready(function() {
$('#<%= dom_id(@quiz) %>').fadeOut();
})
From looking at the Rails s logs, I can see that the delete request comes in and is processed by the js, so my best guess is it's either an issue with div_for and dom_id OR my js is bad (highly likely).