0

I have a route /changepassword and I need to add to it 2 params: iduser and resetcode. To look like this: /changepassword?iduser=123&resetcode=foo

I read other things related to this (1, 2) but I couldn't figure this out. I don't have any experience in ember and I was ask to do some modifications where I work. We are using ember 1.5.1

I tried this but it's throwing me this: Uncaught Error: Assertion Failed: Error: Assertion Failed: The URL '/changepassword?test1=aaasd' did not match any routes in your application

[EDIT]

Thanks to @GJK, I know that what I need is query params, no path params.

Now, my code looks like this:

Routes:

module.exports = App.Router.map ->
      ...
      ...
      @resource('change_password', path: '/changepassword')

Controller:

module.exports = App.ChangePasswordController = Ember.Controller.extend

  needs: ['config', 'viewport', 'application']

  queryParams: ['test']
  test: null
  ...
  ...

But, when I access http://localhost:3333/#/changepassword?test=foo is transitioning to: http://localhost:3333/#/changepassword


[OLD]

This are my routes:

module.exports = App.Router.map ->
  @resource 'index', path: '/', ->
  @resource('account_sign_up', path: '/signup')
  @resource('unsubscribe', path: '/unsubscribe')
  @resource('change_password', path: '/changepassword/:test1/:test2')

Any help? Thanks!

Community
  • 1
  • 1
Mati Tucci
  • 2,826
  • 5
  • 28
  • 40
  • 3
    It looks like you want to use [query parameters](http://guides.emberjs.com/v2.1.0/routing/query-params/) but you're declaring path parameters in your route. These have very different semantics. You should read about query parameters to see if they'll work for your use case. (The big difference is that you do not have access to them in your route's `model` hook.) – GJK Oct 13 '15 at 13:59
  • @GJK but I don't need to add the params in my route? Thanks – Mati Tucci Oct 13 '15 at 14:27
  • No, query parameters are declared on the controller, not the route. – GJK Oct 13 '15 at 14:28
  • @GJK Oh, ok. But now if I access `changepassword?test=foo` the site is redirecting me to `changepassword`. That's ok? – Mati Tucci Oct 13 '15 at 14:37
  • Do you have the `test` query parameter declared on your controller? Ember manages your query parameters now, it's not going to allow a bad query parameter to stay in the URL. – GJK Oct 13 '15 at 14:46
  • @GJK Yes, I have it. I just edited my question with my code – Mati Tucci Oct 13 '15 at 15:16
  • How to you normally access this route? Can you have it always accessible by an {{action}} or by call to transitionto ? – Dory Zidon Oct 15 '15 at 16:42

1 Answers1

0

There are two possible ways to do this:

1) Use the params variable with multiple parameters:

@resource('change_password', path: '/changepassword/:iduser/:resetcode')

model : function (params) {
  console.log(params.iduser);
  console.log(params.resetcode);    
}

2) Use the http://guides.emberjs.com/v1.10.0/routing/query-params/ (which I'm not sure is available for 1.5)..so I didn't include an example..

Dory Zidon
  • 10,497
  • 2
  • 25
  • 39