Core: Routing issues

Created on 22 Oct 2016  路  5Comments  路  Source: adonisjs/core

I'm have this problem right now with my routes:

Route.resources('customers', 'CustomerController').except('create', 'edit')
     .addCollection('names', 'GET', 'CustomerController.names')

All the urls in the resource work as expected except the collection 'names' which throws an Exception about not finding the id = names in the Customer model and that is because is CustomerController.show is the one trying to process it instead of the one I defined which is CustomerController.names.

I found solution by creating a url before the resource like this:

Route.get('customers/names', 'CustomerController.names')
Route.resources('customers', 'CustomerController').except('create', 'edit')

Most helpful comment

For now you can call addCollection before except, i'll add a fix to make sure collections and members have more priority over resourceful default routes

All 5 comments

For now you can call addCollection before except, i'll add a fix to make sure collections and members have more priority over resourceful default routes

Hi!

I stumbled on this problem too.

This:

Route.resource('tracks', 'TrackController').addCollection('popular')

Is routing to TrackController.show

The suggestion of juanyunis works for now. Looking forward to the fix, way cleaner to use addCollection 馃憤

+1

Removed addCollection and addMember in 4.0, since they are confusing and adds very little value. So it's better to keep routes easy to scan with eyes, over doing magical stuff

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dezashibi picture dezashibi  路  4Comments

itsg2jakhmola picture itsg2jakhmola  路  3Comments

imperez picture imperez  路  4Comments

ghost picture ghost  路  3Comments

themodernpk picture themodernpk  路  3Comments