Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Routing shortcut missbehaviour in engine #6497

Closed
2called-chaos opened this Issue · 5 comments

6 participants

Sven Pachnit Piotr Sarnacki Katrina Owen Luiz Felipe G. Pereira Steve Klabnik Rafael Mendonça França
Sven Pachnit

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

Piotr Sarnacki
Collaborator

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.

Piotr Sarnacki drogus was assigned
Katrina Owen

@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')
Luiz Felipe G. Pereira

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.

Luiz Felipe G. Pereira

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?

Steve Klabnik
Collaborator

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

Luiz Felipe G. Pereira Draiken referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
Luiz Felipe G. Pereira Draiken referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
Rafael Mendonça França rafaelfranca closed this issue from a commit
Luiz Felipe G. Pereira 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
Something went wrong with that request. Please try again.