Created
October 31, 2013 16:59
-
-
Save bryanaka/7253198 to your computer and use it in GitHub Desktop.
IronRouter and Meteor Subscription Problems
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | |
}); | |
}); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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'}); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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