Hey everyone…me again . I recently got my ember-cli up and running with css,scss,js, and jquery. Everything works just fine until I add
return this.store.find('element');
into my routes model. I am using ember-cli mocks to serve up the json. Here is my elements mock and model:
Mock:
module.exports = function(app) {
var express = require('express');
var elementsRouter = express.Router();
elementsRouter.get('/', function(req, res) {
res.send({
'elements': [{
id: 1,
thumbnail: 'http://lorempixel.com/100/100/abstract/',
title: 'Moorors Epic Stripe',
author: 'Mooror',
rating: 2,
date: '1999-05-18',
description: 'Its just to epic to talk about',
type:'stripe',
},
{
id: 2,
thumbnail: 'http://lorempixel.com/100/100/abstract/',
title: 'For The Forg',
author: 'Ben Forg',
rating: 4,
date: '1912-08-12',
description: 'its just for doing neat stuff',
type:'stripe',
},
{
id: 3,
thumbnail: 'http://lorempixel.com/100/100/abstract/',
title: 'Jim for the win',
author: 'Jim Blake',
rating: 5,
date: '1999-05-15',
description: 'This one is practical',
type:'stripe',
},
{
id: 4,
thumbnail: 'http://lorempixel.com/100/100/abstract/',
title: 'Js son is cool',
author: 'Json',
rating: 1,
date: '1859-07-28',
description: 'json plugin for making cool noises with your mouth',
type:'stripe',
},
{
id: 5,
thumbnail: 'http://lorempixel.com/100/100/abstract/',
title: 'Js son is cool',
author: 'Json',
date: '1859-07-28',
description: 'json plugin for making cool noises with your mouth',
type:'stripe',
}]
});
});
elementsRouter.post('/', function(req, res) {
res.status(201).end();
});
elementsRouter.get('/:id', function(req, res) {
res.send({
'elements': {
id: req.params.id
}
});
});
elementsRouter.put('/:id', function(req, res) {
res.send({
'elements': {
id: req.params.id
}
});
});
elementsRouter.delete('/:id', function(req, res) {
res.status(204).end();
});
app.use('/api/elements', elementsRouter);
};
Model:
import DS from "ember-data";
export default DS.Model.extend({
title: DS.attr('string'),
author: DS.attr('string'),
thumbnail: DS.attr('string'),
rating: DS.attr('number', {defaultValue: 0}),
date: DS.attr('string', {defaultValue: function() { return new Date();}}),
description: DS.attr('string'),
type: DS.attr('string')
});
And as for the actual js I am using app.imports for my plugins and then using inline script code for initializing them (using ember-cli-inline-content). Here’s my inline code:
$( document ).ready(function() {
$(document).foundation();
$(".placeholder-container").click(function(){
var modalName = $(this).data('component-type');
window.location.href='/modals/' + modalName;
});
$(".edit-element").html('<i class="icon-plus-circled"></i>');
$(".edit-element").click(function(){
var modalName = $(this).data('component-type');
window.location.href='/modals/' + modalName;
});
$('#rate').raty({
starOff : 'star-off.png',
starOn : 'star-on.png',
readOnly: true,
score: function() {
return $(this).attr('data-score');
},
path: 'assets/images/'
});
});