guirec@optik360.com
https://rarwe-demo.pagefrontapp.com
<!-- app/templates/bands.hbs -->
<div class="col-md-4">
<div class="list-group">
<div class="list-group-item">
{{input type="text" class="new-band" placeholder="New band"
value=newName insert-newline="createBand" }}
<button class="btn btn-primary btn-sm new-band-button"
{{action "createBand"}}
disabled={{disabled}}>Add</button>
</div>
{{#each model as |band|}}
{{#link-to "bands.band.songs" band class="list-group-item band-link"}}
{{band.name}}
<span class="pointer glyphicon glyphicon-chevron-right"></span>
{{/link-to}}
{{/each}}
</div>
</div>
// app/routes/bands.js
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.store.findAll('band');
},
afterModel() {
Ember.$(document).attr('title', 'Bands - Rock & Roll');
},
actions: {
createBand() {
let route = this, controller = this.get('controller');
let band = this.store.createRecord('band', {
name: controller.get('newName')
});
band.save().then(function() {
controller.set('newName', '');
route.transitionTo('bands.band.songs', band);
});
}
}
});
// app/models/band.js
import DS from 'ember-data';
export default DS.Model.extend({
name: DS.attr('string'),
songs: DS.hasMany('song'),
});
// app/router.js
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: config.locationType
});
Router.map(function() {
this.route('bands', function() {
this.route('band', { path: ':id' }, function() {
this.route('songs');
});
});
});
export default Router;
Angular | Ember |
---|---|
Simple Adaptable Facilement intégrable Plus populaire |
Rapide à développer Meilleure structure Performance |
Apprenez Angular de toute façon
class Article < ActiveRecord::Base
has_many :comments
belongs_to :author
end
class ArctileSerializer < ActiveModel::Serializer
attributes :title
belongs_to :author
end
Active Model Serializer
ActiveModelSerializers.config.adapter = :json_api
ActiveModelSerializers::SerializableResource.new(article).as_json
ActiveModelSerializers::Deserialization.jsonapi_parse(params)
C'est pas du Ruby!
Code Source
Doc bien faite
Stabilité sans stagnation
Pionier du web
Suivez le guide
Livres :
Documentation
Code source
Demandez moi!
guirec@optik360.com