Skip to content

Instantly share code, notes, and snippets.

@josevalim
Created November 16, 2008 12:59
Show Gist options
  • Save josevalim/25476 to your computer and use it in GitHub Desktop.
Save josevalim/25476 to your computer and use it in GitHub Desktop.
diff --git a/actionpack/lib/action_controller/routing/route_set.rb b/actionpack/lib/action_controller/routing/route_set.rb
index ff44849..f3a4f09 100644
--- a/actionpack/lib/action_controller/routing/route_set.rb
+++ b/actionpack/lib/action_controller/routing/route_set.rb
@@ -170,18 +170,24 @@ module ActionController
def #{selector}(*args)
#{generate_optimisation_block(route, kind)}
+ locale = #{route.segment_keys.include?(:locale) ? '{ :locale => I18n.locale || I18n.default_locale }' : '{}'}
+
opts = if args.empty? || Hash === args.first
args.first || {}
else
options = args.extract_options!
- args = args.zip(#{route.segment_keys.inspect}).inject({}) do |h, (v, k)|
+
+ segments = #{route.segment_keys.inspect}
+ #{'segments.delete(:locale) if segments.size > args.size' if route.segment_keys.include?(:locale)}
+
+ args = args.zip(segments).inject({}) do |h, (v, k)|
h[k] = v
h
end
options.merge(args)
end
- url_for(#{hash_access_method}(opts))
+ url_for(#{hash_access_method}(locale.merge(opts)))
end
protected :#{selector}
end_eval
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment