Permalink
Browse files

Added delete to the index view

  • Loading branch information...
chrishalebarnes committed Feb 17, 2015
1 parent 6658a8a commit 85e1569767eb96615c1588f518cadee0e46a1077
@@ -1,7 +1,17 @@
Cars.CarsIndexRoute = Ember.Route.extend({
model: function() {
return this.store.findAll('car');
}
},
actions: {
delete: function(car) {
car.deleteRecord();
car.save().then(function(response) {
console.log('Success!')
}).catch(function() {
console.log('Failure!')
});
}
}
});
Cars.CarsShowRoute = Ember.Route.extend({
@@ -7,6 +7,7 @@
<th>Model</th>
<th>Color</th>
<th>Condition</th>
<th></th>
</tr>
</thead>
<tbody>
@@ -16,6 +17,11 @@
<td>{{car.model}}</td>
<td>{{car.color}}</td>
<td>{{car.condition}}</td>
<td>
<button {{action 'delete' car}} type="button" class="button alert tiny">
Delete
</button>
</td>
</tr>
{{/each}}
</tbody>
@@ -1,5 +1,5 @@
class CarsController < ApplicationController
before_action :set_car, only: [:show, :update]
before_action :set_car, only: [:show, :update, :destroy]
def index
respond_to do |format|
@@ -34,6 +34,16 @@ def create
end
end
def destroy
respond_to do |format|
if @car.destroy
format.json { render json: Car.all, status: :ok }
else
format.json { render json: @car.errors, status: :unprocessable_entity }
end
end
end
private
def set_car
@car = Car.find(params[:id])

0 comments on commit 85e1569

Please sign in to comment.