I first apologize if my questions sounds fully, but I am completely new in Rails and I am not sure what is happening in the framework at all.
I am reading a book about "Ruby on Rails" and I need simply to remove some rows from table when button is clicked. The JavaScript I have added in the assets/javascript/*.js.coffee is as follows:
if $("#cart").length is 1
$("#cart").hide "blind",
direction: "vertical"
, 1000
$("#cart tr").not(".total_line").remove()
The original JavaScript (since I am new to coffee js I have used a online converter to transform it and I am not sure if it is correct):
if ($('#cart').length == 1) { $('#cart').hide("blind", {direction: "vertical" }, 1000); }
$('#cart tr').not('.total_line').remove();
I have added in the destroy method of the controller:
format.js {}
and now the how method looks like:
def destroy
#@cart = Cart.find(params[:id])
#@cart.destroy
@cart = current_cart
@cart.destroy
session[:cart_id] = nil
respond_to do |format|
#format.html { redirect_to store_url,notice: 'Your cart is currently empty' }
format.js { }
format.html { redirect_to store_url }
format.json { head :no_content }
end
end
but it gives me the following error (after button that should call the js is clicked):
Template is missing
Missing template carts/destroy, application/destroy with {:locale=>[:en], :formats=>[:js, :html], :handlers=>[:erb, :builder, :coffee]}. Searched in: * "/home/gotqn/Aptana Projects/depot/app/views"
After some search I found this question Template is missing in which it it said that I need to redirect to somewhere in my methods. I simply try writing:
format.js {head :no_content }
I an truly the error does not appear again, but the JavaScript is not executed.
I really need some help with this issue. Thanks in advance.