Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ember.js: Assertion Failed: An action named 'actionTest' was not found in (generated myroute controller)

I'm trying to use the component bs-button of Ember Bootstrap to dispatch a simple action that will write something in the log. For this, I've created a new app using ember-cli and installed ember-bootstrap according the project Github page.

Then, I've created a route using ember-cli (ember g route myroute) and wrote the code below:

app/routes/myroute.js

import Ember from 'ember';

export default Ember.Route.extend({

  actions: {
    actionTest(value){
      console.log('on actionTest:', value);
    }
  }

});

app/templates/myroute.hbs

{{#bs-button onClick=(action "actionTest")}}Run test action{{/bs-button}}

But when I try to access, the following error appears in console (nothing is rendered):

message: "Assertion Failed: An action named 'actionTest' was not found in (generated myroute controller)"

Followed by:

Uncaught TypeError: Cannot read property 'getAttribute' of undefined

Maybe a completely stupid error, but I haven't found nothing on docs neither on examples.

Environment:

ember-cli:

$ ember -v
ember-cli: 2.10.1
node: 6.9.2
os: darwin x64

chrome console:

DEBUG: -------------------------------
DEBUG: Ember      : 2.10.2
DEBUG: Ember Data : 2.11.3
DEBUG: jQuery     : 3.1.1
DEBUG: -------------------------------
like image 342
Rafael Trestini Avatar asked Nov 15 '25 15:11

Rafael Trestini


1 Answers

I believe by design, the event is only sent to a corresponding controller or component, as mentioned (though not explicitly) in the actions documentation.

So one solution would be to create a myroute controller (or create a component to encapsulate the behavior), and declare the action there.

Otherwise you could include the ember-route-action-helper and reach your action with something like:

{{#bs-button onClick=(route-action "actionTest")}}Run test action{{/bs-button}}
like image 76
roger Avatar answered Nov 18 '25 19:11

roger