Making Emberfire app restful

24 views
Skip to first unread message

Breon Knight

unread,
Jun 3, 2016, 3:24:44 PM6/3/16
to Firebase + EmberJS
I'm having a difficult time understanding how to create my routes.

For example, how would the below be implemented.

/food/:id

/state/:state_id/citys

Tim Stirrat

unread,
Jun 3, 2016, 4:36:52 PM6/3/16
to Breon Knight, Firebase + EmberJS
Hi Breon,

That's more of a general Ember question, not specific to EmberFire, but lets see if I can give you some tips with links to the official docs.

For the first one you can define it as a standard route with a dynamic segment:

// app/router.js
Router.map(function() {
  this.route('food', {path: '/food/:food_id'});
  // ...

and for the second one you'd need nested routes:

  this.route('state', {path: '/state/:state_id'}, function() {
    // note there is an implied sub route called 'index' here
    this.route('cities'); // templates at /
  });

Now that you have defined the routes, you can access the dynamic parameters in the route files:

// app/routes/state.js
export default Ember.Route.extend({
  model(params) {
    return this.store.findRecord('state', params.state_id);
  }
});

Hope that gives you enough to get it working.

Happy coding 🔥

Tim


--
You received this message because you are subscribed to the Google Groups "Firebase + EmberJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-embe...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tim Stirrat

unread,
Jun 3, 2016, 4:38:00 PM6/3/16
to Breon Knight, Firebase + EmberJS
That comment should  have read:

    this.route('cities'); // templates at templates/state/cities.hbs

Breon Knight

unread,
Jun 3, 2016, 6:59:44 PM6/3/16
to Firebase + EmberJS, breonk...@gmail.com
Thanks Tim,

I was really overthinking all of this. This really clarified a lot of things for me.
Reply all
Reply to author
Forward
0 new messages