jeudi 1 octobre 2015

findRecord giving error "Cannot read property '_internalModel' of undefined"

In our ember app, we are using following versions of ember-data and ember-data-factory-guy.

package.json

"ember-cli": "^1.13.8",
"ember-data": "1.13.9",
"ember-data-factory-guy": "1.13.10",

Note: we are using active-model adapter, not yet migrated to the json-api adapter.

import ActiveModelAdapter from 'active-model-adapter';
export default ActiveModelAdapter.extend({

Route: item.js

export default Ember.Route.extend(({
  model(params) {
    return this.store.findRecord('item', params.item_id);
  }
});

Its working fine in development mode, but while running test cases, am facing following issue:

Test Case for "display single item" fails with following error:

{
  "message": "Cannot read property '_internalModel' of undefined",
  "name": "TypeError"
}

ember-data/lib/system/stpre/finder.js, fails at return statement

return promise.then(function (adapterPayload) { Ember.assert("You made a request for a " + typeClass.typeClassKey + " with id " + id + ", but the adapter's response did not have any data", adapterPayload);

return store._adapterRun(function () {
  var requestType = get(serializer, 'isNewSerializerAPI') ? 'findRecord' : 'find';
  var payload = normalizeResponseHelper(serializer, store, typeClass, adapterPayload, id, requestType);
  //TODO Optimize
  var record = pushPayload(store, payload);
  return record._internalModel;
});

(http://ift.tt/1henvBR)

Are we missing anything here? Can anyone please help me to resolve this? I have tried by upgrading versions to latest, but still facing same issue.




Importing vendor JS file into Ember-CLI route file

I have an Ember CLI project, and one of my routes starts like:

import Ember from 'ember';
import Activity from '../models/activity';

var ACCESS_KEY = gOptions.access_key;

export default Ember.Route.extend({
...

I have a file vendor/local_config.js that contains machine-specific information, and is in the .gitignore to be omitted from the repository. It contains:

var gOptions = {
    access_key: 'abcde'
};

In my ember-cli-build.js file, I have imported this file like so:

app.import('vendor/local_config.js');

Running this application, everything works perfectly. The gOptions is universally available.

However, JSHint complains:

routes/activities.js: line 4, col 25, 'gOptions' is not defined.

I'm very new to Ember - what is the preferred method for updating my route to ensure that the vendor-provided classes are properly resolved/detected when JSHint is examining my routes/models?

Or: Is there a superior/Ember-like way of providing locally-defined environment variables, that should not be shared to a team?




Ember.js creating model action

1) I've created a model user.js
2) I submit the form that executes the controller register.js
3) I'am saving a user, using user.save()
4) after that I get an error that: POST http://localhost:4200/users 404 (Not Found)

I've tried to create a route called 'users', but it didn't helped, I've also put a route 'users' in the file router.js, still I get this error, can anyone tell me please what I should do to solve it?




How to add a class to the selected component?

I have a list of components (all the same)

<ul class="search-results">
  {{#each res as |item|}}
    {{search-result item=item}}
  {{/each}}
</ul>

I'd like to add a class on the clicked element, and, when a new element is clicked, the old element should become "unclicked" (aka, remove the class).

Which is the best way to obtain this result?




NPM test error on ember CLI

I was trying to test the app using npm test inside my ember application i ran through following error. How could i find which line has caused the error? Thanks in advance .

enter image description here

My system is ubuntu 14.0.4TLS

My node version is :

node -v : v0.12.7

ember -v : 1.13.1

npm: 2.12.1

phantomjs -v :1.9.0




Render recursive structures - unclosed tag error

I have some problems rendering dropdown menu with Ember.js and HtmlBars. Data I have for menu is in array, something like this:

[{name: 'A', lvl: 0}, {name: 'B', lvl: 1}, {name: 'C', lvl: 0}, {name: 'D', lvl: 1}, , {name: 'E', lvl: 1}]

which should result in following html

<ul>
  <li> <a> A </a> 
    <ul>
      <li> <a> B </a> </li>
    </ul>
  </li>
  <li> <a> C </a> 
    <ul>
      <li> <a> D </a> </li>
      <li> <a> E </a> </li>
    </ul>
  </li>
</ul>

and it would have following structure(with css it will become nice dropdown)

  • A
    • B
  • C
    • D
    • E

The problem is that HTMLbars does not allow following structures

{{#if (condition1)}}
  <ul class="d-menu" data-role="dropdown">
{{/if}}

{{#if (condition2)}}
  </ul>
{{/if}}

Now, I am aware that this is not a bug, but project decision, but I am unsure how to overcome that limitation and to do what I need? The only option I currently see is to generate html string in js code, as I am not allowed to change data model format. If it is possible to replace HTMLbars with something different, it would be acceptable solution for me.




mercredi 30 septembre 2015

Webpack ember-templates-loader

does webpack ember-templates-loader loads all templates (*.hbs) automatically into Ember.TEMPLATES, or do I need to explicitly write require('ember-templates!./templates/my-view.hbs') into my code before bundling?

Thanks.