Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

router becomes mad when using two depth nested namspace or I do it wrong way? #9697

Closed
googya opened this Issue · 10 comments

5 participants

@googya

routes.rb

namespace :api do
   namespace :articles do
      get :show
   end

   namespace :admin do
      namespace :articles do
         get :show
      end
   end
end

log

Started GET "/api/admin/articles/show?id=51403b983e2adbdf14000002&access_token=PhZ0ue89nkk5K5vGewBexw" for 127.0.0.1 at 2013-03-13 17:00:46 +0800
Processing by Api::ArticlesController#show as /

Api::ArticlesContoller#show

params  =>{"id"=>"51403b983e2adbdf14000002",
"access_token"=>"PhZ0ue89nkk5K5vGewBexw",
"action"=>"show",
"controller"=>"api/admin/articles",
"format"=>"json"}

The log shows that request want to access /api/admin/articles/show and It was processed by Api::ArticlesController.
Maybe I made a mistake, someone please could point it out?

@senny
Owner

the "match shorthand" feature has some issues. We can't always guess the right controller name. You can pass controller: "" to get to specify what controller should process the request.

This could be related to a change I made #9374. I'll take a look at your situation and report back.

@pixeltrix
Owner

@googya does the Api::Admin::ArticlesController actually exist? If it doesn't then the Ruby constant lookup mechanism will find Api::ArticlesController the first time it tries, but then fail on the second attempt, e.g:

>> Api::Admin::ArticlesController
=> Api::ArticlesController
>> Api::Admin::ArticlesController
NameError: uninitialized constant Api::Admin::ArticlesController

The router code keeps hold of a reference so the first constant lookup will persist for subsequent requests.

BTW, is this Rails 4.0.0.beta1 or 3.2.12 ?

@strzalek
Collaborator

I can confirm that this issue exists. I had same problem the other day and it was on 3.2.x app.

I can try reproduce it again on my app and provide more details if needed.

@senny
Owner

@strzalek what do you confirm? The behaviour that @pixeltrix described? As far as I know this is just how the lookup is performed and it is expected behaviour not a bug.

@strzalek
Collaborator

Sorry, I wasn't clear. Let me rephrase. I've faced quite similar issue where I had controllers in same namespace and named route with the same name as those controller. I will try to reproduce that in a minute and provide you more details. In the end it will be a bit different case that described in this ticket, which I wrongly assumed was the same.

Sorry once again for confusion.

@strzalek
Collaborator

Ok, I couldn't reproduce "mine" error. There's a big chance that it was my fault.

@senny
Owner

@strzalek thanks for the update.

@googya does the description of @pixeltrix match your situation?

@googya

@senny Maybe, but I am not sure. I will give a try tomorrow!
thanks

@senny
Owner

@googya it's been two months, did you have time to verify this issue?

@steveklabnik
Collaborator

@googya I'm going to give this a close until you have time to reproduce, since @strzalek can't reproduce his similar-sounding issue. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.