Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Implement deleting an event

  • Loading branch information...
commit e020586d1b8b67d9ecd273afc4d199bea8c5463f 1 parent 19de01b
Nicholas Henry authored
9 app/assets/javascripts/views/event_view.js.coffee
... ... @@ -1,8 +1,17 @@
1 1 class App.EventView extends Backbone.View
2 2 model: App.Event
3 3 tagName: "li"
  4 + events:
  5 + "submit form" : "deleteEvent"
4 6
5 7 render: ->
6 8 template = App.TemplateProvider.applyTemplate("events","line_item", @model)
7 9 $(@el).html(template)
8 10 @
  11 +
  12 + deleteEvent: (e)->
  13 + e.preventDefault()
  14 + id = $(e.currentTarget).attr("action").match(/\/events\/(\w*)/)[1]
  15 + deadEvent = eventCollection.get(id);
  16 + deadEvent.destroy()
  17 + false
6 app/assets/templates/events/line_item.jst.hamlc
... ... @@ -1,11 +1,11 @@
1 1 %span.del_form
2 2 %div
3   - %form.button_to{:method => "post", :action => "/events/#{@id}"}
  3 + %form.button_to{:method => "post", :action => "/events/#{@_id}"}
4 4 %input{:name => "_method", :type => "hidden", :value => "delete"}
5 5 %input{:data-confirm => "Are you sure?", :type => "submit", :value => "X" }
6 6 %div.clear
7 7 %span.event_name
8   - %a{:href => "/events/#{@id}/edit"}= @name
  8 + %a{:href => "/events/#{@_id}/edit"}= @name
9 9 %span.event_details
10   - %a{:href => "/events/#{@id}"}Show Details
  10 + %a{:href => "/events/#{@_id}"}Show Details
11 11 %span.event_description= @description
6 app/controllers/events_controller.rb
@@ -36,6 +36,10 @@ def update
36 36 def destroy
37 37 event = current_user.events.find(params[:id])
38 38 event.destroy
39   - redirect_to events_path
  39 +
  40 + respond_with(event) do |format|
  41 + format.html { redirect_to events_path }
  42 + format.json { render :ok }
  43 + end
40 44 end
41 45 end
2  app/views/events/index.html.haml
@@ -17,7 +17,7 @@
17 17 %ul#eventsList
18 18 - for event in @events
19 19 %script
20   - bootstrapEvents.push(new App.Event({ name: "#{event.name}", description: "#{event.description}:", id: "#{event._id}", }));
  20 + bootstrapEvents.push(new App.Event({ name: "#{event.name}", description: "#{event.description}:", _id: "#{event._id}", }));
21 21 %li{:class => @event == event ? :selected : nil}
22 22 %span.del_form
23 23 = button_to "X", event, :confirm => "Are you sure?", :method => :delete

0 comments on commit e020586

Please sign in to comment.
Something went wrong with that request. Please try again.