1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Use new ActiveModel::Naming.route_key in polymorphic_routes

This commit is contained in:
Piotr Sarnacki 2010-08-31 23:43:32 +02:00
parent 6e5aed057f
commit 2607def862
2 changed files with 3 additions and 12 deletions

View file

@ -177,8 +177,7 @@ module ActionDispatch
if parent.is_a?(Symbol) || parent.is_a?(String)
parent
else
str = ActiveModel::Naming.plural(parent).singularize
remove_namespace(str, parent)
ActiveModel::Naming.route_key(parent).singularize
end
end
end
@ -186,8 +185,7 @@ module ActionDispatch
if record.is_a?(Symbol) || record.is_a?(String)
route << record
else
route << ActiveModel::Naming.plural(record)
remove_namespace(route, record)
route << ActiveModel::Naming.route_key(record)
route = [route.join("_").singularize] if inflection == :singular
route << "index" if ActiveModel::Naming.uncountable?(record) && inflection == :plural
end
@ -197,13 +195,6 @@ module ActionDispatch
action_prefix(options) + route.join("_")
end
def remove_namespace(string, parent)
if namespace = parent.class.parents.detect { |n| n.respond_to?(:_railtie) }
string.sub!(/#{namespace._railtie.railtie_name}_/, '')
end
string
end
def extract_record(record_or_hash_or_array)
case record_or_hash_or_array
when Array; record_or_hash_or_array.last

View file

@ -436,7 +436,7 @@ class PolymorphicRoutesTest < ActionController::TestCase
def with_namespaced_routes(name)
with_routing do |set|
set.draw do
namespace(name, :shallow_path => nil, :path => nil, :as => nil) do
scope(:module => name) do
resources :blogs do
resources :posts
end