vendor/rails/actionpack/lib/action_controller/polymorphic_routes.rb in radiant-0.8.2 vs vendor/rails/actionpack/lib/action_controller/polymorphic_routes.rb in radiant-0.9.0.rc2

- old
+ new

@@ -74,12 +74,11 @@ if record_or_hash_or_array.kind_of?(Array) record_or_hash_or_array = record_or_hash_or_array.compact record_or_hash_or_array = record_or_hash_or_array[0] if record_or_hash_or_array.size == 1 end - record = extract_record(record_or_hash_or_array) - namespace = extract_namespace(record_or_hash_or_array) + record = extract_record(record_or_hash_or_array) args = case record_or_hash_or_array when Hash; [ record_or_hash_or_array ] when Array; record_or_hash_or_array.dup else [ record_or_hash_or_array ] @@ -96,13 +95,12 @@ else :singular end args.delete_if {|arg| arg.is_a?(Symbol) || arg.is_a?(String)} + named_route = build_named_route_call(record_or_hash_or_array, inflection, options) - named_route = build_named_route_call(record_or_hash_or_array, namespace, inflection, options) - url_options = options.except(:action, :routing_type) unless url_options.empty? args.last.kind_of?(Hash) ? args.last.merge!(url_options) : args << url_options end @@ -151,54 +149,41 @@ def routing_type(options) options[:routing_type] || :url end - def build_named_route_call(records, namespace, inflection, options = {}) + def build_named_route_call(records, inflection, options = {}) unless records.is_a?(Array) record = extract_record(records) route = '' else record = records.pop route = records.inject("") do |string, parent| if parent.is_a?(Symbol) || parent.is_a?(String) string << "#{parent}_" else - string << "#{RecordIdentifier.__send__("plural_class_name", parent)}".singularize + string << RecordIdentifier.__send__("plural_class_name", parent).singularize string << "_" end end end if record.is_a?(Symbol) || record.is_a?(String) route << "#{record}_" else - route << "#{RecordIdentifier.__send__("plural_class_name", record)}" + route << RecordIdentifier.__send__("plural_class_name", record) route = route.singularize if inflection == :singular route << "_" end - action_prefix(options) + namespace + route + routing_type(options).to_s + action_prefix(options) + route + routing_type(options).to_s end def extract_record(record_or_hash_or_array) case record_or_hash_or_array when Array; record_or_hash_or_array.last when Hash; record_or_hash_or_array[:id] else record_or_hash_or_array end - end - - # Remove the first symbols from the array and return the url prefix - # implied by those symbols. - def extract_namespace(record_or_hash_or_array) - return "" unless record_or_hash_or_array.is_a?(Array) - - namespace_keys = [] - while (key = record_or_hash_or_array.first) && key.is_a?(String) || key.is_a?(Symbol) - namespace_keys << record_or_hash_or_array.shift - end - - namespace_keys.map {|k| "#{k}_"}.join end end end