I’m doing some Rails stuff with AJAX (not using UJS, but rather rolling my own AJAX). My action looks like:
# DELETE /votes/1
# DELETE /votes/1.json
def destroy
@vote = Vote.find(params[:id])
Comment.increment @vote.comment_id, :up_votes => -1
@vote.destroy
respond_to do |format|
format.html { redirect_to votes_url }
format.json { head :ok }
end
end
This action is being called via JavaScript ala:
ajaxOptions = {
url: $(this).attr("href"),
type: $(this).attr("data-method"),
data: {
comment_id: $(this).attr("data-comment_id"),
_method: 'delete'
},
success: function(response) {
return someFunc();
}
};
$.ajax(ajaxOptions);
However, what happens is the action redirects to the vote list page. I want it to not redirect at all just return some positive status to the JavaScript so that my someFunc() can execute without issue.
How would I accomplish this?
Change your respond_to handler to Javascript instead of JSON: