coffeescript - Implementing a simple search with Meteor and Iron Router -
in next phase of meteor journey (read: learning ropes!), i'd implement simple search based on user inputed values, redirect route specific record returned server.
at moment, i'm picking inputed values via code:
template.home.events 'submit form': (event, template) -> event.preventdefault() console.log 'form submitted!' countryfirst = event.target.firstcountrysearch.value countrysecond = event.target.secondcountrysearch.value session.set 'countrypairsearchinputs', [countryfirst, countrysecond] countrypairsearchinputs = session.get 'countrypairsearchinputs' console.log(countrypairsearchinputs) return router.go('explore') happily, console log returns desired countrypairsearchinputs variable - array of 2 ids. in routes.coffee file have following:
@route "explore", path: "/explore/:_id" waiton: -> meteor.subscribe 'countrypairssearch' on server side, have:
meteor.publish 'countrypairssearch', getcountrypairssearch and finally, have search.coffee file in /lib directory defines getcountrypairssearch function:
@getcountrypairssearch = -> countrypairs.findone $and: [ { country_a_id: $in: session.get('countrypairsearchinputs') } { country_b_id: $in: session.get('countrypairsearchinputs') } ] with regards search function itself, have countrypairs collection each record has 2 ids (country_a_id , country_b_id) - aim here allow users input 2 countries, corresponding countrypair being returning.
i'm struggling tie pieces - console output on searching currently:
uncaught error: missing required parameters on path "/explore/:_id". missing params are: ["_id"]. params object passed in was: undefined. any appreciated - can tell i'm new meteor , still getting used pub/sub methodology!
edited: mixed client/server publish method when first posted - danger of late-night posting!
first, seems you're expecting :id parameter on 'explore' route.
if understand you're case, you're not expecting params here, can delete ':id' route:
@route "explore", path: "/explore/" waiton: -> meteor.subscribe 'countrypairssearch' or either add params router.go call:
router.go('explore', {_id: youridvar}); secondly, you're trying use client function: session.get() server-side. try update publication using parameter ; or using method.call.
client-side
meteor.subscribe 'countrypairssearch' countrya countryb not sure coffeescript syntax, check http://docs.meteor.com/#/full/meteor_subscribe
and server-side
@getcountrypairssearch = (countrya, countryb) -> countrypairs.findone $and: [ { country_a_id: $in: countrya } { country_b_id: $in: countryb } ]
Comments
Post a Comment