Skip to content

Instantly share code, notes, and snippets.

@joliss
Created May 25, 2012 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save joliss/2788545 to your computer and use it in GitHub Desktop.
Save joliss/2788545 to your computer and use it in GitHub Desktop.
Ember routing example
# Works against Ember HEAD.
# Note the routing still changes a lot. This might not work tomorrow.
window.App = Ember.Application.create()
App.Router = Ember.Router.extend
location: 'hash' # hopefully it will auto-pick and support HTML5 in the future
root: Ember.State.extend
index: Ember.State.extend
route: '/'
connectOutlets: (manager) ->
manager.transitionTo('elections')
elections: Ember.State.extend
route: '/elections'
index: Ember.State.extend
route: '/'
connectOutlets: (manager) ->
show: Ember.State.extend
route: '/:election_id'
modelType: App.Election # this is an ember-data model, which has an id
connectOutlets: (manager, election) ->
console.log(election)
# This auto-instantiates the router class found at App.Router and starts the routing
App.initialize()
@coop
Copy link

coop commented May 25, 2012

I just pulled from master and it's almost working like you describe. On L#14 I have to include the state I want to transition to manager.transitionTo('elections.index') or I get an error "You need to provide an object and key to get".

I've been trying to piece together some working code (from router to view) from both this gist and @wycats one (posted a couple of days ago - https://gist.github.com/2728699) and can't seem to get it right... https://gist.github.com/2791272. If I include:

rootView = Ember.ContainerView.create({
  controller: appController,
  currentViewBinding: 'controller.view'
});
rootView.appendTo('#content');

before the call to appController.connectOutlet(App.UsersView, App.User.find()); the template gets rendered but from what I understood there was a helper called {{outlet}} that I could hook into.

Any thoughts?

@joliss
Copy link
Author

joliss commented May 26, 2012

Yeah, I'm not sure yet what they even mean by outlet, terminology-wise.

I haven't hooked up controllers and views with my routing yet, but I'm expecting there's some kind of pattern this is meant to be used with. I'll go have a stab at it on Monday night. Maybe some gists or docs will have turned up by then, else I'll ask around on #emberjs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment