Skip to content

Instantly share code, notes, and snippets.

@bryanaka
Created October 31, 2013 16:59
Show Gist options
  • Save bryanaka/7253198 to your computer and use it in GitHub Desktop.
Save bryanaka/7253198 to your computer and use it in GitHub Desktop.
IronRouter and Meteor Subscription Problems
Meteor.publish('travelRequests', function() {
return TravelRequests.find({}, {
fields: {
'first_name': true,
'last_name' : true,
'email' : true,
'depart_on' : true,
'return_on' : true,
'status' : true
}
});
});
Meteor.publish('singleTravelRequest', function(id) {
return TravelRequests.find({_id: id});
});
Router.configure({
layoutTemplate: 'layout',
notFoundTemplate: '404',
loadingTemplate: 'loading'
});
Router.map(function() {
this.route('home', {
path: '/',
template: 'travel',
controller: 'TravelController',
action: 'index'
});
this.route('newTravel', {
path: '/travel/new',
controller: 'TravelController',
action: 'new'
});
this.route('editTravel', {
path: '/travel/:_id/edit',
controller: 'TravelController',
action: 'edit'
});
// this was switched between ShowTravelController, and TravelController#show for each repective case
this.route('showTravel', {
path: '/travel/:_id',
controller: 'ShowTravelController'
});
this.route('travel', {
path: '/travel',
controller: 'TravelController',
action: 'index'
});
});
// TravelController.show was commented out when using this controller
ShowTravelController = ApplicationController.extend({
waitOn: function() {
var id = this.params._id;
return [Meteor.subscribe('singleTravelRequest', id)];
},
action: function() {
// tried this one too
// this.waitOn = Meteor.subscribe('singleTravelRequest', this.params._id);
this.data = TravelRequests.findOne({_id: this.params._id});
this.render();
this.render('travelNav', {to: 'topNav'});
}
});
TravelController = ApplicationController.extend({
waitOn: function() {
var id = this.params._id;
return [Meteor.subscribe('travelRequests'), Meteor.subscribe('singleTravelRequest', id)];
},
index: function() {
this.renderTravel();
},
new: function() {
this.renderTravel();
},
// this show action is commented out when using ShowTravelController
show: function() {
this.data = TravelRequests.findOne({_id: this.params._id});
this.renderTravel();
},
edit: function() {
this.data = TravelRequests.findOne({_id: this.params._id});
this.renderTravel();
},
renderTravel: function() {
this.render();
this.render('travelNav', {to: 'topNav'});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment