Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save thomas-kielbus/5942778 to your computer and use it in GitHub Desktop.
Save thomas-kielbus/5942778 to your computer and use it in GitHub Desktop.
Allow foo_path(foo) even with :locale prefix in routes in Rails 4.
unless Rails::VERSION::STRING == "4.0.0"
raise "Rails version changed. Revisit overrides and make sure they're still good!"
end
# If routes are prefixed with a :locale, you can no longer do
# `foo_path(foo)` but only `foo_path(id: foo)`, since it expects
# the first of any non-hash arguments to be the locale.
# This monkeypatch fixes that by never allowing locale as the first
# non-hash argument
module HandlePositionalArgsWithLocalePrefix
def handle_positional_args(t, args, options, keys)
if keys && keys[0] == :locale
keys << keys.shift
end
super
end
end
module ActionDispatch
module Routing
class RouteSet
class NamedRouteCollection
class UrlHelper
prepend HandlePositionalArgsWithLocalePrefix
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment