Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ember 2.10 undefined route dynamic segment no longer working. #14657

Closed
arenoir opened this issue Nov 30, 2016 · 22 comments
Closed

ember 2.10 undefined route dynamic segment no longer working. #14657

arenoir opened this issue Nov 30, 2016 · 22 comments

Comments

@arenoir
Copy link

arenoir commented Nov 30, 2016

This looks more like a unsupported feature than a bug but I thought I would log it.

When upgrading from 2.9.1 to 2.10 I ran into the following exception.

"Assertion Failed: You attempted to define a `{{link-to "timecards"}}` but did not pass the parameters required for generating its dynamic segments. You must provide param `login` to `generate`."
#app/router.js
this.route('timecards', {path: '/timecards/:login'}, function() {
  this.route('index', { path: '/' });
  this.route('timecard-day', {path: '/day/:date'});
  this.route('pay-period', {path: '/pay-period/:date'});
});

#app/routes/timecards.js #model hook
model(params) {    
  let login = params.login || this.get('currentUser.login');
  return this.store.peekAll('user').findBy('login', login);
}

It was quite handy to use a optional dynamic segment on the parent route to load a default user model rather than having to load it for each individual child routes.

@rwjblue
Copy link
Member

rwjblue commented Nov 30, 2016

I'm fairly sure you can still do this by passing undefined and implementing a custom serialize hook.

The error message added here is a pretty big win for folks in general, and I'd prefer to keep it around if possible...

@sly7-7
Copy link
Contributor

sly7-7 commented Nov 30, 2016

@rwjblue passing undefined to the link-to helper throws this warning: This link-to is in an inactive loading state because at least one of its parameters presently has a null/undefined value, or the provided route name is invalid.

@Exelord
Copy link
Contributor

Exelord commented Nov 30, 2016

I had also issues with:

{{link-to 'projects.project.tasks' project}}
  this.route('projects', function() {
    this.route('project', { path: ':id' }, function() {
      this.route('tasks');
    });
  });

The Ember error told about undefined id.
The quick fix for that was to change :id in router to :project_id

I think that it's not real fix and it deserves to be qualified as a bug. Otherwise, there was no information about changing router behavior.

@locks
Copy link
Contributor

locks commented Dec 2, 2016

@Exelord that is unrelated to the originally described bug, and not a bug. We specifically document that the default implementation requires :modelname_id to work out of the box. If you are using a custom field, you will have to reimplement serialize/deserialize in the respective route.

@pixelhandler
Copy link
Contributor

@Exelord (as a sidenote, not directly related to this issue)... I'm not sure if this is documented or not but I don't think you can use the same identifier for a dynamic segment more than once in the router. So I'd avoid using ":id", and also avoid using ":modelname_id" more than once. (e.g. if needed again maybe use ":newmodelname_id", just something different)

@pixelhandler
Copy link
Contributor

@rwjblue @sly7-7 so it appears there is not a clean work-around for this issue, correct?

@pixelhandler
Copy link
Contributor

@arenoir can you make an ember-twiddle reproduction of this issue, it sounds like a bug. Having a repo of the issue will help diagnose the issue and also provide the verification of the bug.

@Exelord
Copy link
Contributor

Exelord commented Dec 2, 2016

@locks @pixelhandler
You have a right, guys. Thanks for help and explanation. But indeed it was working before 2.10.
I guess now, it was a bug or unexpected behavior.

@arenoir
Copy link
Author

arenoir commented Dec 6, 2016

@pixelhandler okay here is a twiddle.

@dustinfarris
Copy link

dustinfarris commented Dec 29, 2016

☝️ looks like a good reproduction. that label can be removed

@bjornharrtell
Copy link

I'm confused as to if this is to be regarded a regression or if I should fix in application.

@carlbennettnz
Copy link

This is blocking 2.10 and 2.11 for us. Happy to attempt a fix if someone can confirm this is a regression.

@asvny
Copy link
Contributor

asvny commented Mar 20, 2017

Same problem for me as described by @arenoir

@jakeleboeuf
Copy link

Running into this same issue today 👎

@tarikozket
Copy link

tarikozket commented May 5, 2017

@jakeleboeuf I was having the same issue and upgrading to 2.13.1 fixed it. Which version do you have?

[EDIT]
It's 2AM here and my brain is almost gone to deep space. I just realized I tested it wrong. It's still continuing...

@alvincrespo
Copy link
Contributor

In case anyone runs into this issue, could possibly be this:

import Controller from 'ember';
import { alias } from 'ember-computed';

export default Controller.extend({
  deployments: alias('model')
});

Note that I am importing Contoller incorrectly. It should be import Controller from 'ember-controller';. This is if you are using ember-cli-shims, which is what my current project is using. I was lost on this for about an hour before I gave up, came back and saw clearly what I was doing wrong.

@lrdiv
Copy link

lrdiv commented Jun 16, 2017

Long shot here, but I ran into this issue when accidentally overriding the native Object with Ember's Object class via something like:

const { Object } = Ember;

This was causing my model hook (where Object.create is called) to fail and, for some reason, the exception thrown mentioned dynamic segments not being present. I think this is similar to what @alvincrespo mentions in his comment above.

@brunowego
Copy link

@lrdiv yeah, I think this happening with me to.

Assertion Failed: You attempted to define a `{{link-to "control.templates.show"}}` but did not pass the parameters required for generating its dynamic segments. _ember.default.extend is not a function

@lrdiv
Copy link

lrdiv commented Jun 19, 2017

@brunowego Yeah that's the same error I was getting. In our case it seems that this is more of a misleading exception than an actual bug.

@nightsh
Copy link

nightsh commented Jul 7, 2017

@lrdiv this was also happening to me, good catch! ✌️

What I was doing was to destructure Ember and precisely override the native Object with what was otherwise an Ember.Object. So I changed the name into something like const EmberObject = Ember.Object in the declaration and usage and all went the right way. I wouldn't call it a bug-bug either, so I agree with you on pretty much everything you wrote above 😜

@pixelhandler
Copy link
Contributor

@Exelord @acorncom @alvincrespo @arenoir @asvny @bjornharrtell @brunowego @carlbennettnz @dustinfarris @jakeleboeuf @locks @lrdiv @nightsh @rwjblue @sly7-7 @tarikozket is this still an issue, perhaps we should close or create a new reproduction of this, what do you think?

@pixelhandler
Copy link
Contributor

Closing for now, feel free to re-open if you can reproduce in the current release of Ember.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests