sunoceansand
sunoceansand

Reputation: 237

Ember controller: nothing handled the action

I looked through related posts for hours, but could not find the right answer to fix the problem I'm having.

I keep getting the error:

Uncaught Error: Nothing handled the action 'edit'. If you did handle the action, this error can be caused by returning true from an action handler in a controller, causing the action to bubble.

I think that the controller is handling things wrong, or it's bubbling up to a wrong route?

App.EventDetailsController = Ember.ObjectController.extend({
   isEditing: false,

actions: {
    edit: function() {
        this.set('isEditing', true);
    },

    doneEditing: function() {
        this.set('isEditing', false);
    }
    }
});


App = Ember.Application.create();

    App.Router.map(function() {
   // put your routes here
  this.route('events', {path: '/events'});
  this.route('createevent', {path: '/createevent'});
  this.route('eventdetails', {path: ':eventdetails_id'});
});

App.EventsRoute = Ember.Route.extend({
model: function() {
    return events;
}
});

App.EventDetailsRoute = Ember.Route.extend({
model: function(params) {
    return events.findBy('id', params.eventdetails_id);
}
});

Does anyone know why this wouldn't work?

Upvotes: 8

Views: 8582

Answers (4)

JKP
JKP

Reputation: 3

I have also faced similar problem. But in my case, I have called a route action from a controller action in which, I have used transitionToRoute.

Since the transition to another route was finished even before the completion of route action, the error was thrown " Nothing handled the action actionName. If you did handle the action, this error can be caused by returning true from an action handler in a controller, causing the action to bubble".

Reference: https://discuss.emberjs.com/t/sending-action-from-current-controller-to-current-route/6018

Upvotes: 0

Ravi Kumar
Ravi Kumar

Reputation: 1

This problem is caused when our template and controller name is different. Please check your template and controller name

Upvotes: 0

Jamie Chong
Jamie Chong

Reputation: 842

You probably want to define your routes like this:

App.Router.map(function() {
    this.resource('events', function() {                            // /events         <-- your event listing
        this.resource('event', {path: ':event_id'}, function() {    // /events/1       <-- your event details
            this.route('edit');                                     // /events/1/edit  <-- edit an event
        }); 
        this.route('create');                                       // /events/create  <-- create your event
    });
});

But aside from that, note that actions bubble up through the Routes, so try moving your actions handler to the EventDetailsRoute instead.

Read the part in the guide that talks about it here: http://emberjs.com/guides/templates/actions/#toc_action-bubbling

App.EventDetailsRoute = Ember.Route.extend({
    actions: {
        edit: function() {
            this.set('isEditing', true);
        },

        doneEditing: function() {
            this.set('isEditing', false);
        },

        //or maybe better:
        toggleEditing: function() {
            this.toggleProperty('isEditing');
        }
    },

    model: function(params) {
        return events.findBy('id', params.eventdetails_id);
    }
});

Upvotes: 2

hackerrdave
hackerrdave

Reputation: 6706

I have a suspicion it has to do with not using the proper naming conventions. If your route's name is EventDetailsRoute then the route should be referenced in the router as event-details.

Upvotes: 0

Related Questions