I'm using rails 4 and backbone in my app. I created delete method with Backbone, but when I try to delete using it, I get this error:
DELETE http://localhost:3000/[object%20Object] 400 (Bad Request)
My delete method:
deleteBook: (ev) ->
@model.destroy()
)
Events:
events:
"click .delete": "deleteBook"
Pressing on that error, it shows that model type is text/html
. So I suppose I have to convert it to json?
If I do like this:
deleteBook: (ev) ->
@model.toJSON().destroy()
)
Update:
My destroy method in rails controller (if it matters):
@book = Book.find(params[:id])
@book.destroy
redirect_to '/'
Update2:
My Backbone model:
$(document).ready ->
window.Book = Backbone.Model.extend(url: ->
(if @id then "/books/" + @id else "/books")
urlRoot: '/books/'
)
Then nothing happens and I won't get any error. So I think I am doing something wrong here?