Skip to content
Permalink
Browse files

Added the new view

  • Loading branch information...
chrishalebarnes committed Feb 17, 2015
1 parent aa7ed78 commit 6658a8a1e833d491fd3bf00a74deca78f3103949
@@ -1,7 +1,8 @@
// For more information see: http://emberjs.com/guides/routing/

Cars.Router.map(function() {
this.resource('cars', function() {
this.route('show', { path: '/:id' });
this.resource("cars", function() {
this.route('show', { path: '/:id' });
this.route('new');
});
});
@@ -19,4 +19,29 @@ Cars.CarsShowRoute = Ember.Route.extend({
});
}
}
});

Cars.CarsNewRoute = Ember.Route.extend({
model: function() {
return this.store.createRecord('car', {});
},
deactivate: function() {
var model = this.modelFor(this.routeName);
model.rollback();
},
actions: {
save: function(model) {
var self = this;
model.save().then(function(response) {
console.log('Success!');
//transition back to index
//self.transitionTo('cars.index');

//transition to the saved new car
self.transitionTo('cars.show', response);
}).catch(function() {
console.log('Failure!');
});
}
}
});
@@ -10,7 +10,7 @@
</tr>
</thead>
<tbody>
{{# each car in model}}
{{# each car in model}}
<tr>
<td>{{#link-to 'cars.show' car.id}} {{car.make}} {{/link-to}}</td>
<td>{{car.model}}</td>
@@ -20,4 +20,7 @@
{{/each}}
</tbody>
</table>
<div class="actions">
{{#link-to 'cars.new' class='button success' }} Add {{/link-to}}
</div>
</div>
@@ -0,0 +1,41 @@
<div id="cars-new" class="panel">
<h1>New 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>
@@ -23,6 +23,17 @@ def update
end
end

def create
@car = Car.new(car_params)
respond_to do |format|
if @car.save
format.json { render json: @car, status: :created }
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 6658a8a

Please sign in to comment.
You can’t perform that action at this time.