diff options
author | T.J. Schuck <tj@getharvest.com> | 2014-12-06 01:17:50 -0500 |
---|---|---|
committer | T.J. Schuck <tj@getharvest.com> | 2014-12-06 01:17:50 -0500 |
commit | ee65f48c2666a660cc48496c8bc9f63113a41e44 (patch) | |
tree | 41febd3a1be378302f338a0fcbe228ce533855fb /actionpack/lib/action_dispatch/routing/mapper.rb | |
parent | 785d04e3109f69d0b9b9f4732179592f0ef04e52 (diff) | |
download | rails-ee65f48c2666a660cc48496c8bc9f63113a41e44.tar.gz rails-ee65f48c2666a660cc48496c8bc9f63113a41e44.tar.bz2 rails-ee65f48c2666a660cc48496c8bc9f63113a41e44.zip |
Mounted Rack apps should have default named routes based on app name
This fixes a regression in 4.2.0 from 4.1.8.
https://github.com/rails/rails/pull/17823 fixed a similar regression regarding _explicitly_ named routes for a mounted Rack app, but there was another regression for the default value.
With a route like:
Rails.application.routes.draw do
mount Mountable::Web, at: 'some_route'
end
The "Prefix" column of rake routes gives the following:
- 4.1.8: mountable_web
- 4.2.0.beta1-4: [nothing]
- 4.2.0.rc1: [nothing]
- 4.2.0.rc2: some_route <- regression
This fixes the default to go back to being based off the name of the class like the docs specify: https://github.com/rails/rails/blob/785d04e3109f69d0b9b9f4732179592f0ef04e52/actionpack/lib/action_dispatch/routing/mapper.rb#L558-L560
Explicitly named routes still work correctly per https://github.com/rails/rails/pull/17823:
Rails.application.routes.draw do
mount Mountable::Web, at: 'some_route', as: 'named'
end
- 4.1.8: named
- 4.2.0.beta1-4: [nothing]
- 4.2.0.rc1: [nothing]
- 4.2.0.rc2: named
Diffstat (limited to 'actionpack/lib/action_dispatch/routing/mapper.rb')
-rw-r--r-- | actionpack/lib/action_dispatch/routing/mapper.rb | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 5040aa82b2..f07a4aa674 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -579,15 +579,14 @@ module ActionDispatch raise "A rack application must be specified" unless path - rails_app = rails_app? app - options[:as] ||= app.railtie_name if rails_app + options[:as] ||= app_name(app) target_as = name_for_action(options[:as], path) options[:via] ||= :all match(path, options.merge(:to => app, :anchor => false, :format => false)) - define_generate_prefix(app, target_as) if rails_app + define_generate_prefix(app, target_as) if rails_app?(app) self end @@ -612,6 +611,14 @@ module ActionDispatch app.is_a?(Class) && app < Rails::Railtie end + def app_name(app) + if rails_app?(app) + app.railtie_name + elsif class_name = app.try(:name) + ActiveSupport::Inflector.underscore(class_name).tr("/", "_") + end + end + def define_generate_prefix(app, name) _route = @set.named_routes.get name _routes = @set |