# Controller needs

**URL:** <https://discuss.emberjs.com/t/controller-needs/3905>\
**Category:** Uncategorized\
**Created:** [January 19, 2014, 6:11pm UTC](https://discuss.emberjs.com/t/controller-needs/3905 "2014-01-19T18:11:13Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![jamalsoueidan](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/jamalsoueidan/32/234_2.png) [@jamalsoueidan](https://discuss.emberjs.com/u/jamalsoueidan)\
**Post date:** [January 19, 2014, 6:11pm UTC](https://discuss.emberjs.com/t/controller-needs/3905/1 "2014-01-19T18:11:13Z")

</div>

Hello everyone,

I have this controller.

```
App.ContactsController = Ember.ArrayController.extend({
  isShowNew: false
})

```

I want to access isShowNew from another controller, so I thought I could use needs property in another controller.

```
App.ContactsNewController = Ember.Controller.extend({
  needs: "contacts",
  actions: {
    create: function() {
      console.log(this.controllers) 
      console.log(this.get('controllers').contacts) //undefined
    }
  }
});

```

But all I’m getting is undefined?

---

<div class="post-metadata">

**Author:** ![jamalsoueidan](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/jamalsoueidan/32/234_2.png) [@jamalsoueidan](https://discuss.emberjs.com/u/jamalsoueidan)\
**Post date:** [January 19, 2014, 7:01pm UTC](https://discuss.emberjs.com/t/controller-needs/3905/2 "2014-01-19T19:01:23Z")

</div>

This worked.

```
this.get('controllers.contacts')

```

---

<div class="post-metadata">

**Author:** ![tarasm](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/tarasm/32/15980_2.png) [@tarasm](https://discuss.emberjs.com/u/tarasm)\
**Post date:** [January 20, 2014, 1:35am UTC](https://discuss.emberjs.com/t/controller-needs/3905/3 "2014-01-20T01:35:09Z")

</div>

Why do you need access to contacts controller?

---

<div class="post-metadata">

**Author:** ![jamalsoueidan](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/jamalsoueidan/32/234_2.png) [@jamalsoueidan](https://discuss.emberjs.com/u/jamalsoueidan)\
**Post date:** [January 20, 2014, 8:39am UTC](https://discuss.emberjs.com/t/controller-needs/3905/4 "2014-01-20T08:39:44Z")

</div>

Because in “ContactsController” i have attribute isVisible I want to set to false so I can hide the “contactsNewView” from “contactsView”.

---

<div class="post-metadata">

**Author:** ![tarasm](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/tarasm/32/15980_2.png) [@tarasm](https://discuss.emberjs.com/u/tarasm)\
**Post date:** [January 20, 2014, 2:48pm UTC](https://discuss.emberjs.com/t/controller-needs/3905/5 "2014-01-20T14:48:46Z")

</div>

You could bubble up the action instead.

```javascript

App.ContactsController = Ember.Controller.extend({
  actions: {
    create: function() {
      this.set('isShowNew', false);
    }
  }
});

App.ContactsNewController = Ember.Controller.extend({
  actions: {
    create: function() {
      // do your stuff here
      return true; // will bubble this action up to the controller above
    }
  }
});

```

Also, keep in mind that you’d probably want to handle persisting of the created contact in the router instead of the controller.

---

<div class="post-metadata">

**Author:** ![jamalsoueidan](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/jamalsoueidan/32/234_2.png) [@jamalsoueidan](https://discuss.emberjs.com/u/jamalsoueidan)\
**Post date:** [January 20, 2014, 6:12pm UTC](https://discuss.emberjs.com/t/controller-needs/3905/6 "2014-01-20T18:12:29Z")

</div>

Well I tried to handle create in the ContactsController in the first place but it doesn’t work ☹

I removed the create action from App.ContactsNewController, but the action doesn’t bubble for some reason.

> Uncaught Error: Nothing handled the action ‘create’. 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.

```
App.ContactsController = Ember.ArrayController.extend({
  actions: {
    create: function() {
      console.log('contactS')
    }
  }
});

App.ContactController = Ember.ObjectController.extend({
  actions: {
    create: function() {
      console.log('contact')
    }
  }
});

```

Just in case you want to know how I dispatched the action is through

```
App.ContactsNewView = Ember.View.extend({
  submit: function(evt) {
    evt.preventDefault();
    this.get('controller').send('create')
    return false;
  }
})

```

---

<div class="post-metadata">

**Author:** ![tarasm](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/tarasm/32/15980_2.png) [@tarasm](https://discuss.emberjs.com/u/tarasm)\
**Post date:** [January 20, 2014, 6:30pm UTC](https://discuss.emberjs.com/t/controller-needs/3905/7 "2014-01-20T18:30:30Z")

</div>

Right, my mistake, from controller it will bubble to the closest route and then up the routes.

---

<div class="post-metadata">

**Author:** ![jamalsoueidan](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/jamalsoueidan/32/234_2.png) [@jamalsoueidan](https://discuss.emberjs.com/u/jamalsoueidan)\
**Post date:** [January 20, 2014, 7:06pm UTC](https://discuss.emberjs.com/t/controller-needs/3905/8 "2014-01-20T19:06:57Z")

</div>

Actually it’s not your mistake 😃

Something is wrong since it never bubbles to the Route.

I would rather put all the actions in the Route instead of using every single controller to handle it.

[http://embersherpa.com/articles/crud-example-app-without-ember-data](http://embersherpa.com/articles/crud-example-app-without-ember-data)

He is using version 1.0, and he can get the actions to go up to the ApplicationRoute.

Weird!

```
<form>
  <label>State</label>
  {{input value=state type="text"}}
  <br />

  <button {{action 'create'}}>Create</button>
</form>

```

---

<div class="post-metadata">

**Author:** ![jamalsoueidan](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/jamalsoueidan/32/234_2.png) [@jamalsoueidan](https://discuss.emberjs.com/u/jamalsoueidan)\
**Post date:** [January 20, 2014, 7:13pm UTC](https://discuss.emberjs.com/t/controller-needs/3905/9 "2014-01-20T19:13:37Z")

</div>

This is my app inspector

This is HIS app inspector

---

<div class="post-metadata">

**Author:** ![jamalsoueidan](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/jamalsoueidan/32/234_2.png) [@jamalsoueidan](https://discuss.emberjs.com/u/jamalsoueidan)\
**Post date:** [January 20, 2014, 7:38pm UTC](https://discuss.emberjs.com/t/controller-needs/3905/10 "2014-01-20T19:38:54Z")

</div>

I figure it out 😃

I just need to use the INDEX view 🙂

---

<div class="post-metadata">

**Author:** ![tarasm](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/tarasm/32/15980_2.png) [@tarasm](https://discuss.emberjs.com/u/tarasm)\
**Post date:** [January 20, 2014, 7:58pm UTC](https://discuss.emberjs.com/t/controller-needs/3905/11 "2014-01-20T19:58:53Z")

</div>

Ember Sherpa is me BTW.

---

<div class="post-metadata">

**Author:** ![jamalsoueidan](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/jamalsoueidan/32/234_2.png) [@jamalsoueidan](https://discuss.emberjs.com/u/jamalsoueidan)\
**Post date:** [January 20, 2014, 8:47pm UTC](https://discuss.emberjs.com/t/controller-needs/3905/12 "2014-01-20T20:47:44Z")

</div>

This is funny 😃

Talking to the same guy who made the sample I’m looking at to create my application 😃 and you are trying to help me 2 hehe.

Thank you 😃

---

<div class="post-metadata">

**Author:** ![tarasm](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/tarasm/32/15980_2.png) [@tarasm](https://discuss.emberjs.com/u/tarasm)\
**Post date:** [January 20, 2014, 10:26pm UTC](https://discuss.emberjs.com/t/controller-needs/3905/13 "2014-01-20T22:26:11Z")

</div>

You’re welcome and welcome to Ember community 😉
