xamenrax
xamenrax

Reputation: 1744

Ember.js routing, can't access controller

I have started small ember application, I have view:

Cellar.SearchTextField = Ember.TextField.extend({
    insertNewline: function(){
      Cellar.SearchController.loadResults();
    }
});

and controller:

Cellar.SearchController = Ember.ArrayController.create({
  content: [],
  searchQuery: "",
  loadResults: function() {
    var me = this;
    SC.get('/tracks', { q: me.get('searchQuery') }, function(tracks) {
      me.set('content', []);
      $(tracks).each(function(index, value){
        var track = Cellar.Track.create({
          id: value.id,
          artwork: value.artwork_url,
          download_url: value.download_url,
          duration: value.duration,
          stream_url: value.stream_url
        })
        me.pushObject(track);
      });
    });
  }
});

and an application template:

<div class="navbar navbar-inverse navbar-fixed-top">
  <div class="navbar-inner">
    <div class="container"></div>
      <h3 class="logo">{{#linkTo "index"}}Cellar{{/linkTo}}</h3>

      <form class="navbar-search">
        {{view Cellar.SearchTextField placeholder="search" valueBinding="Cellar.SearchController.searchQuery"}}
      </form>

    </div>
  </div>
</div>
<div id="content">
{{outlet}}
</div>

my problem is when I am on the route http://localhost:3000/ my searchController doesn't work, but it's all okay when URL is http://localhost:3000/#/, why?

Upvotes: 1

Views: 135

Answers (1)

Darshan Sawardekar
Darshan Sawardekar

Reputation: 5075

The Ember default is to use the hash based routes. You can change that by reopening the Router and switching to HTML5 location api.

App.Router.reopen({
  location: 'history'
});

Edit: I think there is a version mismatch here. This appears to be an older version of ember.

In the current version, you do not create a controller instead manually. You provide a controller and extend either ArrayController or ObjectController.

You won't have a reference to an App.SearchController anymore. You can either send events or call a method on the controller via the {{action}} helper.

There are quite a few differences, I'd suggest giving the Ember Getting Started Guide a quick read to refresh up on the changes.

Upvotes: 1

Related Questions