Skip to content Skip to sidebar Skip to footer

Backbone Remove Row By Id

I'm trying to remove a row in a table with Backbone. I'm using Rails 4 and the backbone-on-rails gem for this project. I'm using a addEntryevent to add row in my Movies table. This

Solution 1:

So apparently @collection.remove doesn't put out a HTTP request. Changing this to @collection.get(thisid).destroy() does the trick. But you will still need to create a destroy method in your Rails controller,

The removeEntry event in the Backbone view index,

removeEntry: (e) -> 
  thisid = @$(e.currentTarget).closest('div').data('id')
  @collection.get(thisid).destroy()

The destroy method in the Rails controller,

defdestroy
  movie = Movie.find_by_id(params[:id])
  movie.destroy

  respond_to do|format|
    format.json {render :json => {:msg => "item deleted!"},:status => 200}
  endend

Post a Comment for "Backbone Remove Row By Id"