I am creating an application which lets applicants apply through a form. The form must auto-generate a new application if no previous application was passed in.
My router.js
file:
Router.map(function () {
this.route("apply", {path: ":application_id"}, function () {
/* ... */
});
});
And my routes/apply.js
export default Ember.Route.extend({
model: function(params) {
if (params["application_id"]) {
console.dir(params.application_id);
return this.store.find("application", params.application_id);
}
else {
console.dir(params);
let emptyApplicant = this.store.createRecord("applicant", {isPrimary: true}), emptyApplication = this.store.createRecord("application");
emptyApplication.set("applicant", emptyApplicant);
return emptyApplication;
}
}
});
But navigating to /apply
gives me the following error:
Error while processing route: apply.index Couldn't find record of type 'application' for the id 'apply'. Error: Couldn't find record of type 'application' for the id 'apply'. at DS.LSAdapter.DS.Adapter.extend.find
I checked what the params
is, and it is apply
in this case (I was expecting it to be null
, and the url apply/7g2c7
to be 7g2c7
).
How can I detect when an application ID is being sent in, and auto-generate a new application otherwise?
Aucun commentaire:
Enregistrer un commentaire