I am having trouble using the query-params-new feature.
My version of ember is 1.4.0-beta.2.
Ember.js is loaded into my rails app through the ember-rails and ember-source gems.
Before initializing the Ember App I turn on the feature like so.
Ember.FEATURES["query-params-new"] = true
After doing so I get the following error when navigating to any route.
Error while loading route: TypeError: Object [object Object] has no method 'paramsFor' at Ember.Route.Ember.Object.extend.deserialize
Am I missing something? Do I need to define a paramsFor method at each route?
I'm having the same problem, I noticed this issue mentioning the problem, and attributes it to misusing the new query params API. Where you using the prior implementation?
Edit:
My problem was how I was enabling it.
I was following the prior method of simply passing a value to Ember.FEATURES:
Ember.FEATURES['query-params-new'] = true;
However, the docs now specify the correct method (which also needs to happen before the Ember js file is loaded by the browser):
ENV = {FEATURES: {'query-params-new': true}};
I forgot coffee-script wraps everything in a top-level function.
Here is the way I do it in coffee-script.
#= require_self
#= require handlebars
#= require ember
#ENV = {FEATURES: {'query-params-new': true}}
Related
I'm getting the following error:
Uncaught TypeError: Cannot read property 'extend' of undefined
when I try to use:
Ember.View.extend
I read that Views have been removed, what should I use instead?
Thanks,
Katie.
Ember.Views are deprecated from Ember 2.0. But still it can be used with the support of their ember-legacy-views addon. Even this addon will be only compatible for the versions before v2.4.The object Ember.CoreView from which Ember.Views is extended is also deprecated.
So the best way is to use Ember.Component. Like Views, Components are too re-usable and isolated from others with its own context with the template.
Refer for more info on Ember.View deprecation and steps to migrate from Views to Components
Store.push(type, data) has been deprecated. Please provide a JSON-API document object as the first and only argument to store.push
I've just updated to ember 1.13.2 and ember-data 1.13.3 and I'm now receiving lots of the deprecation message mentioned in this post's title. I don't know what is causing it to appear and the Ember Inspector's Deprecations tab doesn't show me where in my code the issue is located.
If anyone can explain to me what the message means and what I need to do to resolve it I'd be grateful.
Thanks.
UPDATE:
My custom application adapter looks like this:
// app/adapters/application.js
import ActiveModelAdapter from 'active-model-adapter';
export default ActiveModelAdapter.extend({
host: 'http://dev.mydomain.com',
namespace: 'api/v1',
});
It uses the ActiveModelAdapter add-on as a different deprecation message explained that the ActiveModelAdapter will no longer be bundled with ember-data as of v2.0.0. However, I have tried my code with both the ember-data adapter and the add on and I get the same deprecation message about Store.push.
There are a few stack traces as there are multiple versions of the same deprecation but here are a couple:
DEPRECATION: store.push(type, data) has been deprecated. Please provide a JSON-API document object as the first and only argument to store.push.
at ember$data$lib$system$store$$Service.extend.push (http://localhost:4200/assets/vendor.js:81014:17)
at http://localhost:4200/assets/vendor.js:83253:17
at Array.forEach (native)
at Ember.Mixin.create._extractEmbeddedHasMany (http://localhost:4200/assets/vendor.js:83251:68)
at null.<anonymous> (http://localhost:4200/assets/vendor.js:83219:22)
at http://localhost:4200/assets/vendor.js:84254:20
at cb (http://localhost:4200/assets/vendor.js:27380:11)
at OrderedSet.forEach (http://localhost:4200/assets/vendor.js:27163:11)
at Map.forEach (http://localhost:4200/assets/vendor.js:27384:18)
DEPRECATION: store.push(type, data) has been deprecated. Please provide a JSON-API document object as the first and only argument to store.push.
at ember$data$lib$system$store$$Service.extend.push (http://localhost:4200/assets/vendor.js:81014:17)
at Ember.Mixin.create._extractEmbeddedBelongsTo (http://localhost:4200/assets/vendor.js:83302:15)
at null.<anonymous> (http://localhost:4200/assets/vendor.js:83226:22)
at http://localhost:4200/assets/vendor.js:84254:20
at cb (http://localhost:4200/assets/vendor.js:27380:11)
at OrderedSet.forEach (http://localhost:4200/assets/vendor.js:27163:11)
at Map.forEach (http://localhost:4200/assets/vendor.js:27384:18)
at Function.ember$data$lib$system$model$$default.reopenClass.eachRelationship (http://localhost:4200/assets/vendor.js:84253:83)
at Ember.Mixin.create._extractEmbeddedRecords (http://localhost:4200/assets/vendor.js:83212:19)
NEW ERROR AFTER ADDING isNewSerailizerAPI: true TO SERIALIZERS (see answers):
Error while processing route: elavonApplication.index Cannot read property 'id' of undefined TypeError: Cannot read property 'id' of undefined
at ember$data$lib$serializers$embedded$records$mixin$$_newExtractEmbeddedBelongsTo (http://localhost:4200/assets/vendor.js:83482:33)
at Ember.Mixin.create._extractEmbeddedBelongsTo (http://localhost:4200/assets/vendor.js:83349:98)
at null.<anonymous> (http://localhost:4200/assets/vendor.js:83419:19)
at http://localhost:4200/assets/vendor.js:84310:20
at Map.forEach.cb (http://localhost:4200/assets/vendor.js:27380:11)
at OrderedSet.forEach (http://localhost:4200/assets/vendor.js:27163:11)
at Map.forEach (http://localhost:4200/assets/vendor.js:27384:18)
at Function.ember$data$lib$system$model$$default.reopenClass.eachRelationship (http://localhost:4200/assets/vendor.js:84309:83)
at ember$data$lib$serializers$embedded$records$mixin$$_newExtractEmbeddedRecords (http://localhost:4200/assets/vendor.js:83413:17)
at Ember.Mixin.create._extractEmbeddedRecords (http://localhost:4200/assets/vendor.js:83265:96)
The JSON returned from the server does contain the "id" field but the serializer seems unable to find it as we get the error and the models are not populated to the Ember store.
The line that fails is:
// assets/vendor.js
var belongsTo = { id: data.id, type: data.type };
And after putting a watch on the "data" variable where the "id" is being looked for it is "undefined". The "data" variable is defined in the code as:
var data = _normalizeEmbeddedRelationship2.data;
So I don't know if this gives any clues considering all the ember-data changes recently?
I also have a deprecation that may be related to the problem which is:
Ember Inspector (Deprecation Trace): Your custom serializer uses the old version of the Serializer API, with `extract` hooks. Please upgrade your serializers to the new Serializer API using `normalizeResponse` hooks instead.
at ember$data$lib$system$store$serializer$response$$normalizeResponseHelper (http://localhost:4200/assets/vendor.js:74034:15)
at http://localhost:4200/assets/vendor.js:75772:25
at Object.Backburner.run (http://localhost:4200/assets/vendor.js:10776:25)
at ember$data$lib$system$store$$Service.extend._adapterRun (http://localhost:4200/assets/vendor.js:81352:33)
at http://localhost:4200/assets/vendor.js:75771:15
at tryCatch (http://localhost:4200/assets/vendor.js:65295:14)
at invokeCallback (http://localhost:4200/assets/vendor.js:65310:15)
at publish (http://localhost:4200/assets/vendor.js:65278:9)
at http://localhost:4200/assets/vendor.js:42094:7
Also, to reiterate I am now using the active-model-adapter add-on instead of the one bundled with ember-data as an earlier deprecation message recommended. Not sure if perhaps this add-on is not compatible with ember-data after all the recent updates to it? (just tested this by reverting back to the original bundled adapter and the same error still occurs).
If you set:
isNewSerializerAPI: true
On your serialiser it should solve the issue.
Ok, the issue seems to have been fixed by the recent ember-data 1.13.4 update. Once I removed our attempted earlier fix of using:
isNewSerializerAPI: true
on the serializers (which caused other issues) and updated to 1.13.4 everything works as it should again.
Thanks for the help offered.
Per the release docs push() now takes a JSON API compatible payload as the only argument. The type that used to be passed into push is present in the JSON API format so that's not needed separately any more. To have this work "out of the box" your API source would have to return valid JSON API JSON data.
If that's not possible, you would need a custom serializer that implements the translation methods to convert your API's JSON format into JSON API format. I think you could do this largely in "normalizeResponse" in the Serializer. Details for making that transition from old Serializer API to new can be found here in the release docs
I'm trying to use moment.js in my ember.js app (built with ember-cli), I have a trouble with this error
Handlebars error: Could not find property 'formatDate' on object
I think it's same as this error How to use Custom helpers in ember-app-kit? but I already did the same approach but not working yet. Anyone got same error? Please help me to figure out.
I put
app.import('vendor/momentjs/moment.js'); in Brocfile.js
and
"moment": true in .jshintrc as in ember-cli documentation,
and I used the helper {{formatDate date}} in PostsTemplate
I created a helper app/helpers/formatDate.js
var formatDate = Ember.Handlebars.makeBoundHelper(function(date) {
return moment(date).fromNow();
});
export default formatDate;
I also tried this syntax in app/helpers/formatDate.js, but neither works and both get same error
export default Ember.Handlebars.registerBoundHelper('formatDate',function(date) {
return moment(date).fromNow();
});
I think your file name 'formatDate.js' has the wrong format. Try 'format-date.js' and it should work.
Excerpt from http://iamstef.net/ember-cli/:
Handlebars helpers will only be found automatically by the resolver if their name contains a dash (reverse-word, translate-text, etc.) This is the result of a choice that was made in Ember, to help both disambiguate properties from helpers, and to mitigate the performance hit of helper resolution for all bindings.
Use your new 'format-date' helper like this:
{{format-date "29/05/2014"}}
I ran into this symptom as well and had a different solution.
I had a helper in app/helpers/fh.js called 'fh' in order to be able to use it I needed to add it to the controller as follows
import fh from '../helpers/fh';
If I didn't have the import line I would get the following error:
"Handlebars error: Could not find property 'fh' on object"
I'm trying to use guard-handlebars to precompile my handlebars templates (to avoid having them all in my index.html, which feels slightly sub-optimal...). The precompilation works well, and Ember accepts the fact that the template accept when I inject it into Ember.TEMPLATES like this:
Ember.TEMPLATES['application'] = Handlebars.templates['application']
However, it doesn't work. I get an exception like this:
Could not find property 'outlet'
...in the Handlebars helperMissing method. It seems like Ember uses some monkey-patching of the default Handlebars stuff, supposedly adding support for the {{outlet}} helper and others. But my template does not seem to use these outlets. How do you work around this?
I'm using the handlebars compiler installed via NPM to compile the templates.
Found a duplicate question with a suggested solution/workaround: How can I consume handlebars command-line generated templates with Ember?
(short summary: yes, precompiling with the handlebars command line program does not work straight away, exactly because of the reason I am suggesting in the original question)
The plugin for you.
(Here's a sample integration: https://github.com/trek/ember-todos-with-build-tools-tests-and-other-modern-conveniences/blob/master/Gruntfile.js)
The guard-handlebars gem is pretty out of date, it was not designed to work with ember.
Today there are a few options.
barber with rake-pipeline
grunt-ember-templates
For example, to compile an ember template with barber try something like this:
compiled_template = Barber::Ember::FilePrecompiler.call(IO.read(file))
# now ruby variable compiled_template is a string like: "Ember.Handlebars.template(function(...));"
result = "Ember.TEMPLATES['#{name}'] = '#{compiled_template}';"
# now result is a JS string that sets Ember.TEMPLATES[name] to precompiled handlebars
When a new version of ember comes out it can take a few days to make it's way thru the ecosystem. When that happens you might find the ember-source gem helpful. See Alex's blog post for more detail:
http://alexmatchneer.com/blog/2013/02/27/gemifying-ember-dot-js-slash-handlebars-dot-js-slash-etc-dot-js/
I'm using Ember built from git master. My RouteManager is not complex, but when I try to start my app, I get this error:
Uncaught TypeError: Property '1' of object , is not a function
Following the trace indicates that this is happening on the app's initialization.
This jsfiddle shows the problem, although you'll have to look in the javascript console to see the error message. My actual router will be more complex than this, but I've pared it down to the bones to try to eliminate potential error sources.
You need to update your version of Ember Data to the latest version from master, as the injection API changed.
Here is a fiddle which "works".
http://fiddle.jshell.net/Sly7/ZySzK/
I pick up an ember-data resource from another fiddle I found on stackoverflow.
The way of populating the arraycontroller is weird. Usually you pass the context in the connectOutlet method of the controller, by specifying a context (in your case, it should be Sylvius.Section.find() )
I don't know why, but doing this, I have the error 'Sylvius.Section has no method find'... perhaps an other mess due to ember-data/emberjs bad version.