Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

route error using scope with 'get' under namespace #7403

Closed
lkmatsumura opened this Issue · 5 comments

3 participants

lkmatsumura Rafael Mendonça França Andrew White
lkmatsumura

Environment:

  • Ruby on Rails v3.2.6
  • Ruby : 1.9.3p194
  • OS: Debian Linux

With the routes.rb below

scope '/test' do
  namespace :admin do
    resource :users do
      member do
        put :team_update
      end
    end

    get 'mailer/preview'

  end
end

Produce the following routes

team_update_admin_users PUT    /test/admin/users/team_update(.:format) admin/users#team_update
            admin_users POST   /test/admin/users(.:format)             admin/users#create
        new_admin_users GET    /test/admin/users/new(.:format)         admin/users#new
       edit_admin_users GET    /test/admin/users/edit(.:format)        admin/users#edit
                        GET    /test/admin/users(.:format)             admin/users#show
                        PUT    /test/admin/users(.:format)             admin/users#update
                        DELETE /test/admin/users(.:format)             admin/users#destroy
   admin_mailer_preview GET    /test/admin/mailer/preview(.:format)    test/admin/mailer#preview

I think the correct routing parameters for the route for the line get 'mailer/preview' is admin/mailer#preview (Without the 'test/' string)

With the workaround of explicitly specifying the route:

  .
  .
  .
    get 'mailer/preview' => "mailer#preview"

Then the routes work as expected:

team_update_admin_users PUT    /test/admin/users/team_update(.:format) admin/users#team_update
            admin_users POST   /test/admin/users(.:format)             admin/users#create
        new_admin_users GET    /test/admin/users/new(.:format)         admin/users#new
       edit_admin_users GET    /test/admin/users/edit(.:format)        admin/users#edit
                        GET    /test/admin/users(.:format)             admin/users#show
                        PUT    /test/admin/users(.:format)             admin/users#update
                        DELETE /test/admin/users(.:format)             admin/users#destroy
   admin_mailer_preview GET    /test/admin/mailer/preview(.:format)    admin/mailer#preview
Rafael Mendonça França

Could you test with 3.2.8?

lkmatsumura

Oh, my fault, tested just now, this occur with 3.2.8 too

Andrew White
Owner

This is expected behaviour - the shorthand syntax uses the path to work out what the controller should be. As you discovered, explicitly specifying the controller works.

Andrew White pixeltrix closed this
lkmatsumura

Ok, I can live with this, but IMHO this behavior is not consistent.

namespace :prefix do
  get 'mailer/test'
end

and

scope "/prefix" do
  get 'mailer/test'
end

both routes to prefix/mailer#test (IMHO wrong result for scope)

But, similarly

namespace :prefix do
  get 'mailer/test' => 'mailer#test'
end

and

scope "/prefix" do
  get 'mailer/test' => 'mailer#test'
end

routes to prefix/mailer#test and mailer#test respectively

So get 'mailer/test' and get 'mailer/test' => 'mailer#test' under namespace produces the same result and under scope produces diferent results. Not so much consistent behaviour.
And if I understood the concept of scope, the prefix can´t be added to resultant route.

Andrew White
Owner

What you have to remember is that path != controller - if you don't specify the controller then it will guess a controller based on the current path but while it seems obvious to remove the prefix in the simple case once you get a couple of nested namespaces and scopes determining what should and shouldn't be in the controller becomes tricky - especially if a :path option has been supplied as that makes the module different from the path.

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.