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

@ -177,8 +177,7 @@ def build_named_route_call(records, inflection, options = {})
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 @@ def build_named_route_call(records, inflection, options = {})
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 @@ def build_named_route_call(records, inflection, options = {})
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

@ -436,7 +436,7 @@ def test_uncountable_resource
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