Ember Data Mockjax
HTML
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery-mockjax/1.5.2/jquery.mockjax.js"></script>
<script src="http://ember.alexspeller.com/handlebars-1.0.0.js"></script>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<script src="http://ember.alexspeller.com/canary/shas/5c30be4fe354b57a9241be6cd14f0b3fae977c0e/ember.js"></script>
<script src="http://ember.alexspeller.com/canary/shas/45d196b2907ae0ddca2ffc2b50ce84fbc0e275c6/ember-data.js"></script>
<script type="text/x-handlebars">
< div class = "container" > < form {
{
action "updateUser"
on = "submit"
}
} > < h2 > Create User < /h2>
{{form-field label="Name" value=name}}
{{form-field label="Email" value=email}}
{{form-field label="Password" value=password}}
{{form-field label="Password Confirmation" value=passwordConfirmation}}
<button class="btn btn-primary btn-block" type="submit">Save</button >
< /form>
</div >
</script>
<script type="text/x-handlebars" data-template-name="components/form-field">
< div class = "form-group" > < label {
{
bind - attr
for = label
}
} > {
{
label
}
} < /label>
{{input type=type value=value id=label class="form-control"}}
</div >
</script>
CoffeeScript
window.App = Em.Application.create()
# The newly added component object:
App.FormFieldComponent = Em.Component.extend
type: (->
if @get('label').match(/password/i)
"password"
else
"text"
).property 'label'
App.ApplicationAdapter = DS.ActiveModelAdapter.extend()
App.ApplicationRoute = Em.Route.extend
model: ->
@store.createRecord 'user'
actions:
updateUser: ->
alert "Updating user #{@currentModel.get 'name'}"
App.User = DS.Model.extend
name: DS.attr 'string'
email: DS.attr 'string'
password: DS.attr 'string'
passwordConfirmation: DS.attr 'string'