Skip to content

Instantly share code, notes, and snippets.

@MichalBryxi
Last active August 29, 2015 13:58
Show Gist options
  • Save MichalBryxi/10126453 to your computer and use it in GitHub Desktop.
Save MichalBryxi/10126453 to your computer and use it in GitHub Desktop.
Ember transition problem
///// Problematic code
{{#each module in controller}}
{{#link-to 'forge-module.show' module}} // <-- here "is" my problem
{{module.name}}
{{/link-to}}
{{/each}}
// Created HTML:
<a id="ember560" class="ember-view" href="#/forge-module/show/stdlib">
<script id="metamorph-23-start" type="text/x-placeholder"></script>stdlib<script id="metamorph-23-end" type="text/x-placeholder"></script>
</a>
///// ^^ This does not work, when link is cliked, console shows following error:
Attempting transition to forge-module.show ember.js:3886
Transition #2: forge-module.show: calling beforeModel hook ember.js:3886
Transition #2: forge-module.show: forge-module.show: resolving provided model ember.js:3886
Transition #2: forge-module.show: calling afterModel hook ember.js:3886
Transition #2: Resolved all models on destination route; finalizing transition. ember.js:3886
Error while loading route: Error: Assertion Failed: ArrayProxy expects an Array or Ember.ArrayProxy, but you passed object
at new Error (native)
at Error.EmberError (http://0.0.0.0:9876/module_management/scripts/vendor.js:10:9297)
at Object.Ember.assert (http://0.0.0.0:9876/module_management/scripts/vendor.js:9:13984)
at EmberObject.extend._setupArrangedContent (http://0.0.0.0:9876/module_management/scripts/vendor.js:16:9360)
at null._arrangedContentDidChange (http://0.0.0.0:9876/module_management/scripts/vendor.js:16:9134)
at applyStr (http://0.0.0.0:9876/module_management/scripts/vendor.js:12:8397)
at sendEvent (http://0.0.0.0:9876/module_management/scripts/vendor.js:10:14427)
at notifyObservers (http://0.0.0.0:9876/module_management/scripts/vendor.js:11:24149)
at propertyDidChange (http://0.0.0.0:9876/module_management/scripts/vendor.js:11:21858)
at iterDeps (http://0.0.0.0:9876/module_management/scripts/vendor.js:11:22608) ember.js:3886
Transition #2: forge-module.show: transition was aborted
///// However this works flawlessly. Transition to different template works:
{{#each module in controller}}
{{#link-to 'forge-module.show' 'direct-module-name'}}
{{module.name}}
{{/link-to}}
{{/each}}
// Created HTML:
<a id="ember548" class="ember-view" href="#/forge-module/show/direct-module-name">
<script id="metamorph-19-start" type="text/x-placeholder"></script>stdlib<script id="metamorph-19-end" type="text/x-placeholder"></script>
</a>
///// Also this works. But this does not really follow Ember manual: http://emberjs.com/guides/templates/links/
{{#each module in controller}}
{{#link-to 'forge-module.show' module.name}} // <-- We use .name as id
{{module.name}}
{{/link-to}}
{{/each}}
// Created HTML:
<a id="ember550" class="ember-view" href="#/forge-module/show/stdlib">
<script id="metamorph-19-start" type="text/x-placeholder"></script>stdlib<script id="metamorph-19-end" type="text/x-placeholder"></script>
</a>
///// Router:
App.ForgeModuleShowRoute = Ember.Route.extend({
model: function(resource) {
return App.ForgeModuleDetail.find(resource);
}
});
///// Controller:
App.ForgeModuleShowController = Em.ArrayController.extend({
versionToInstall: null,
});
///// Model:
App.ForgeModuleDetail = Em.Model.extend({
name: Em.attr(),
description: Em.attr(),
version: Em.attr(),
author: Em.attr(),
availableVersions: Em.attr(),
operatingSystems: Em.attr(),
homepage: Em.attr(),
bugtracker: Em.attr()
});
App.ForgeModuleDetail.url = ENV.restBaseUrl + 'forge-module/show';
App.ForgeModuleDetail.primaryKey = 'name';
App.ForgeModuleDetail.adapter = Em.RESTAdapter.create();
///// Application router:
App.Router.map(function () {
this.resource('forge-module', function() {
this.route('list');
this.route('show', { path: '/show/:name' });
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment