Routing shortcut missbehaviour in engine #6497

Closed
2called-chaos opened this Issue May 26, 2012 · 5 comments

Projects

None yet

6 participants

@2called-chaos
Contributor

I discovered a bug in the routing within (isolated and mountable) engines.

ProftpdUserManager::Engine.routes.draw do
  # without shortcut
  get 'server/traffic' => "server#traffic"

  # with shortcut
  get 'server/traffic'

  resources :users do
    member do
      get 'enable'
      get 'disable'
      get 'credentials'
      get 'overview_traffic'
    end
  end

  root to: 'users#index'
end

Without shortcut routes (as excpected) to proftpd_user_manager/server#index
With the shortcut it routes to server#index it misses the namespace there...

Is this a bug or expected?

Regards,

Sven Pachnit

Member
drogus commented May 27, 2012

This is definitely a bug, but it's not specific to engines. All engine does, is wrapping routes with namespace. I will look into this today.

@drogus drogus was assigned May 27, 2012
Contributor

@drogus Can this be closed?

Does wrapping a route with a namespace essentially mean the same thing as having the following config/routes.rb?

# config/routes.rb
FuzzApp::Application.routes.draw do
  namespace :fuzz do
    get 'server/traffic'
  end
end

With that routes file rake routes has the expected output:

$ rake routes
fuzz_server_traffic GET /fuzz/server/traffic(.:format) fuzz/server#traffic

Also, a routing spec for this claims that it's working.

    { :get => "/fuzz/server/traffic" }.should route_to(:controller => 'fuzz/server', :action => 'traffic')
Contributor
Draiken commented Jul 30, 2012

This is not the issue @kytrinyx the problem is when you are inside a mountable plugin and use the shorthand. By default everything in the engine mountable gets namespaced, but if you use this shorthand, it doesn't.

The problem seems to be this line but I don't know why this check for to_shorthand is there.

Someone with more depth on the routing can probably explain that, else we can remove the || to_shorthand and it should fix this bug.

Contributor
Draiken commented Jul 30, 2012

I removed the || to_shorthand and it fixed the route for me. Ran all the actionpack tests against rails master and they passed. Should I submit a pull request for this?

Member

@Draiken please do, and then we can discuss it there. If you don't want to, let me know and I will.

@rafaelfranca rafaelfranca pushed a commit that closed this issue Sep 19, 2012
@Draiken Draiken Removing to_shorthand from default_controller_and_action. Fixes #6497
When using shortcut routes inside an engine the "to_shorthand" variable
is set to true, causing the module scope of the route to not be applied.
641ea69
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment