Permalink
Browse files

Added the show/edit view.

  • Loading branch information...
chrishalebarnes committed Feb 17, 2015
1 parent dd4ca56 commit aa7ed787c33e78197fa4b4f0e95518e3514f3c2d
@@ -2,5 +2,6 @@
Cars.Router.map(function() {
this.resource('cars', function() {
this.route('show', { path: '/:id' });
});
});
@@ -2,4 +2,21 @@ Cars.CarsIndexRoute = Ember.Route.extend({
model: function() {
return this.store.findAll('car');
}
});
Cars.CarsShowRoute = Ember.Route.extend({
model: function(params) {
return this.store.find('car', params.id);
},
actions: {
save: function(car) {
var self = this;
car.save().then(function(response) {
//you can transition back to index
//self.transitionTo('cars.index');
}).catch(function() {
console.log('Failure!')
});
}
}
});
@@ -12,7 +12,7 @@
<tbody>
{{# each car in model}}
<tr>
<td>{{car.make}}</td>
<td>{{#link-to 'cars.show' car.id}} {{car.make}} {{/link-to}}</td>
<td>{{car.model}}</td>
<td>{{car.color}}</td>
<td>{{car.condition}}</td>
@@ -0,0 +1,41 @@
<div id="cars-show" class="panel">
<h1>Car</h1>
<form {{action 'save' model on="submit"}}>
<div class="row">
<div class="small-3 columns">
<label for="make" class="right inline required">Make</label>
</div>
<div class="small-9 columns">
{{input id="make" type="text" required="" value=make}}
</div>
</div>
<div class="row">
<div class="small-3 columns">
<label for="model" class="right inline required">Model</label>
</div>
<div class="small-9 columns">
{{input id="model" type="text" required="" value=model.model}}
</div>
</div>
<div class="row">
<div class="small-3 columns">
<label for="color" class="right inline required">Color</label>
</div>
<div class="small-9 columns">
{{input id="color" type="text" required="" value=color}}
</div>
</div>
<div class="row">
<div class="small-3 columns">
<label for="condition" class="right inline required">Condition</label>
</div>
<div class="small-9 columns">
{{input id="condition" type="text" required="" value=condition}}
</div>
</div>
<div class="actions">
<button type="submit" class="button success">Save</button>
{{#link-to 'cars.index' class='button alert' }} Cancel {{/link-to}}
</div>
</form>
</div>
@@ -1,7 +1,34 @@
class CarsController < ApplicationController
before_action :set_car, only: [:show, :update]
def index
respond_to do |format|
format.json { render json: Car.all }
end
end
def show
respond_to do |format|
format.json { render json: @car }
end
end
def update
respond_to do |format|
if @car.update(car_params)
format.json { render json: @car, status: :ok }
else
format.json { render json: @car.errors, status: :unprocessable_entity }
end
end
end
private
def set_car
@car = Car.find(params[:id])
end
def car_params
params.require(:car).permit(:id, :make, :model, :color, :condition)
end
end

0 comments on commit aa7ed78

Please sign in to comment.