# What is the correct way to get the current path with slug/id from a controller?

**URL:** <https://discuss.emberjs.com/t/what-is-the-correct-way-to-get-the-current-path-with-slug-id-from-a-controller/7059>\
**Category:** Uncategorized\
**Created:** [January 9, 2015, 7:29pm UTC](https://discuss.emberjs.com/t/what-is-the-correct-way-to-get-the-current-path-with-slug-id-from-a-controller/7059 "2015-01-09T19:29:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mode7James](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/mode7james/32/10099_2.png) [@Mode7James](https://discuss.emberjs.com/u/Mode7James)\
**Post date:** [January 9, 2015, 7:29pm UTC](https://discuss.emberjs.com/t/what-is-the-correct-way-to-get-the-current-path-with-slug-id-from-a-controller/7059/1 "2015-01-09T19:29:52Z")

</div>

I’m sure I’m doing everything incorrect here so your guidance is much appreciated. By the way, I’m using ember-cli with ember-data, and even though I’ve built a few Ember projects I still consider myself pretty novice.

Question #1: It seems like in my ‘categories/category.js’ controller using { needs: [‘application’] } I can trace in Chrome the ‘controllers.application’ object and see a ‘currentPath’ property right there in Chrome dev tools, but then when I trace ‘controllers.application.currentPath’ it returns as ‘undefined’ ??!

I’m trying to get the current page so that I can update a menu dropdown, and so in my ‘category’ controller I’m defining this:

```
onPageChange:function(){
 console.log("Page Change", this.get('controllers.application.currentPath')); // returns 'Page Change undefined'

 console.log("Page Change", this.get('controllers.application')); // returns a Class object that has both 'currentPath' and 'currentRouteName' (shows as 'categories.category'

}.observes('currentPath') // why does this only update if I have 'currentPath' observed, and not 'controllers.application.currentPath'??

```

Question #2: Say I’m able to grab the currentPath, why doesn’t it show the full path with the selected slug? It just shows ‘categories.category’ and not ‘categories.category.my-sub-page’? My routes are:

```
this.resource('categories', {path:'/'}, function(){
		this.route('category', {path: ':category_slug'});
	});

```

---

<div class="post-metadata">

**Author:** ![Mode7James](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/mode7james/32/10099_2.png) [@Mode7James](https://discuss.emberjs.com/u/Mode7James)\
**Post date:** [January 9, 2015, 7:50pm UTC](https://discuss.emberjs.com/t/what-is-the-correct-way-to-get-the-current-path-with-slug-id-from-a-controller/7059/2 "2015-01-09T19:50:45Z")

</div>

So, I powered through to a solution, but I’m sure there’s a more “Ember” way to achieve this, which would be great if someone would like to share.

```
// controllers/categories/category.js

...

categoryCollection:{}, // collection of the categories, which are the slugs used    
onRouteChange:function(){
    		this.set('selectedCategory', this.get('categoryCollection')[this.get('model').category_slug]); // I'm setting the 'selectedCategory' variable that updates a dropdown, which has all of the parent categories as options
    	}.observes('currentPath'),

```

---

<div class="post-metadata">

**Author:** ![jasonmit](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/jasonmit/32/182_2.png) [@jasonmit](https://discuss.emberjs.com/u/jasonmit)\
**Post date:** [January 9, 2015, 9:39pm UTC](https://discuss.emberjs.com/t/what-is-the-correct-way-to-get-the-current-path-with-slug-id-from-a-controller/7059/3 "2015-01-09T21:39:59Z")

</div>

Here is something I threw together to help someone here with a similar question.

> **[Ember Latest - JSFiddle - Code Playground](http://jsfiddle.net/NQKvy/1191/)**
>
> Test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle code editor.

There could be a better way, I’m not sure.
