Created
March 20, 2012 14:52
-
-
Save henrik/2136465 to your computer and use it in GitHub Desktop.
Allow foo_path(foo) even with :locale prefix in routes in Rails 3.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unless Rails::VERSION::STRING == "3.2.2" | |
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, and instead always setting current locale as a | |
# hash option. | |
module HandlePositionalArgsWithLocalePrefix | |
def handle_positional_args(options) | |
pk = options[:_positional_keys] | |
if pk && pk[0] == :locale | |
pk.shift | |
options[:locale] ||= I18n.locale | |
end | |
super | |
end | |
end | |
# Change this to your app name. | |
MyAppName::Application.routes.extend HandlePositionalArgsWithLocalePrefix |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment