> In the meantime, if you want to contribute your patch I can take a
> look at it.
Our situation is that we need a route that can have dynamic segments
without a corresponding static segment. (say /jmcnulty/posts/1 in
stead of /users/jmcnulty/posts/1). The way we implement this in the
routing is like so:
map.user ':id', :controller => 'users', :action => 'show'
map.with_options :path_prefix => ":user_id", :name_prefix => "user_"
do |user|
user.resources :posts, :only => [:index, :show]
end
The problem was in route_enclosing_names which assumes that when it
encounters a dynamic segment, that before that it will have
encountered a corresponding static segment. This assumption is not
true in our case, hence the following hack which checks if the
previous segment was a static one and only modifies the last element
if so, otherwise it adds a new one. The patch only does something
different in the case which originally just broke, therefore I am
confident it does not break anything else.
---
.../lib/ardes/resources_controller.rb | 15 ++++++++++++
+--
1 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/vendor/plugins/resources_controller/lib/ardes/
resources_controller.rb b/vendor/plugins/resources_controller/lib/
ardes/resources_controller.rb
index 06affe6..e6caa99 100644
--- a/vendor/plugins/resources_controller/lib/ardes/
resources_controller.rb
+++ b/vendor/plugins/resources_controller/lib/ardes/
resources_controller.rb
@@ -725,11 +725,22 @@ module Ardes#:nodoc:
#
# This is used to map resources and automatically load
resources.
def route_enclosing_names
+ last_segment_type = nil
@route_enclosing_names ||= returning(Array.new) do |req|
enclosing_segments.each do |segment|
unless segment.is_optional or segment.is_a?
(::ActionController::Routing::DividerSegment)
- req << [segment.value, true] if segment.is_a?
(::ActionController::Routing::StaticSegment)
- req.last[1] = false if segment.is_a?
(::ActionController::Routing::DynamicSegment)
+ if segment.is_a?
(::ActionController::Routing::StaticSegment)
+ req << [segment.value, true]
+ last_segment_type = :static
+ end
+ if segment.is_a?
(::ActionController::Routing::DynamicSegment)
+ if last_segment_type == :static
+ req.last[1] = false
+ else
+ req << [segment.key.to_s.sub('_id','').pluralize,
false]
+ end
+ last_segment_type = :dynamic
+ end
end
end
end
--
1.5.4.4