Hello everyone!
I have a doubt, what happens is that I have a search engine in a template that sends a string of characters, which corresponds to a field called id_investigador. This string is stored and sent to another template with a dynamic path, such as: Router.route (’/results/:id_investigador’, {bla bla bla …});
What I want is that when I redirect to the route /results/ xxx
This xxx is the id_investigador that I entered earlier, and DO NOT show the _id of the document inside the collection, but actually show the id_investigador.
For example, if the searcher enters ABCDEFG, the path is /results/ABCDEFG and not /results/4LqB9DXthBYytbpWr.
It is understood?
I leave the application code below. Thank you very much to all.
Template.buscador.events({
'submit form': function(e) {
e.preventDefault();
var busqueda = {
id_investigador: $(e.target).find('[name="id_investigador"]').val()
};
var errors = validateBusqueda(busqueda);
if (errors.id_investigador)
return Session.set('BusquedaError', errors);
Meteor.call('BusquedaInsert', busqueda, function(error, result) {
if (error)
return throwError(error.reason);
console.log(result.id_investigador)
console.log("========================")
Router.go('results', {id_investigador: result.id_investigador});
});
}
});
Meteor.publish('busquedas', function(id) {
check(id, String)
return Busquedas.find(id);
});
Router.route('/results/:id_investigador', {
name: 'results',
waitOn: function() {
return Meteor.subscribe('busquedas', this.params.id_investigador);
},
data: function() {
return Busquedas.findOne(this.params.id_investigador);
}
});
Meteor.methods({
BusquedaInsert: function(busquedaAttributes) {
check(this.userId, String);
check(busquedaAttributes, {
id_investigador: String
});
var errors = validateBusqueda(busquedaAttributes);
if (errors.id_investigador)
throw new Meteor.Error('invalid-', "You must set a title and URL for your search");
var user = Meteor.user();
var busqueda = _.extend(busquedaAttributes, {
userId: user._id,
author: user.username,
submitted: new Date()
});
var id_busqueda = Busquedas.insert(busqueda);
return {
id_investigador: id_busqueda
};
}
});