javascript - How do I assign a custom ID to a dynamically generated URL with Iron Router in Meteor? -
how have url of dynamically generated post 1 of attributes assigned it? it's name? instead of events/vbmmmw6ymrwxjtxpd url events/name-of-the-event
here's routing far:
router.route('/events/:_id', { name: 'event', data: function() { return events.findone(this.params._id);} });
and schema:
events = new mongo.collection("events"); events.attachschema(new simpleschema({ name: { type: string, label: "name", max: 200 }, crew: { type: string, label: "crew" }, location: { type: string, label: "location" }, date: { type: date, label: "date" }, description: { type: string, label: "wha'appening?", max: 1000 } }));
you should add uniq slug in schema (based on name) like:
events.attachschema(new simpleschema({ slug: { //example: my-name-slug type: string }, (...) }));
and in router:
router.route('/events/:slug', { name: 'event', data: function() { return events.findone({slug: this.params.slug});} });
Comments
Post a Comment