Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8820729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:40:50+00:00 2026-06-14T05:40:50+00:00

I’ve done some research on this topic already, but I don’t seem to be

  • 0

I’ve done some research on this topic already, but I don’t seem to be able to figure it out.

I have followed the official guide to set up I18n, but I just don’t get the default locale to be set properly (when no explicit locale is specified).

# routes.rb
require 'sidekiq/web'

Iq::Application.routes.draw do
  scope "(:locale)", locale: /de|en/ do
    # ...
  end
end

# application_controller.rb
class ApplicationController < ActionController::Base
  before_filter :set_language

  def set_language
    I18n.locale = params[:locale] || I18n.default_locale
  end

  def default_url_options(options = {})
    options.merge!({ :locale => I18n.locale })
  end
end

In the OS X console:

$ rake routes | grep user
...
user GET      (/:locale)/users/:id(.:format)   users#show {:locale=>/de|en/}
...

In the Rails console:

$ Rails c
$ app.users_path
=> "/users"
app.users_path locale: :de
=> "/de/users"
$ app.user_path User.first, locale: :de
=> "/de/users/509fc01d77bb1e6a050000a0"
$ app.user_path User.first
ActionController::RoutingError: No route matches {:action=>"show", :controller=>"users", :locale=>#<User _id: 509fc01d77bb1e6a050000a0, _type: nil, created_at: 2012-11-11 15:11:25 UTC, updated_at: 2012-11-11 15:11:25 UTC, deleted_at: nil, group: "administrator", language: "de", active: true, sign_in_count: 0, name: "sysadmin", email: "support@sientia.ch", encrypted_password: "$2a$10$n/b7sTmUjEMoZI/jvq2jPuaNQqo1R1zbAIPpko9HT9PERagXclrPK", reset_password_token: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, confirmation_token: nil, unconfirmed_email: nil, reset_password_sent_at: nil, remember_created_at: nil, confirmed_at: 2012-11-11 15:11:25 UTC, confirmation_sent_at: nil, current_sign_in_at: nil, last_sign_in_at: nil, save_vertical_menu_visibility_state: nil, contact_id: "509fc01d77bb1e6a0500008c", contact_name: "Sientia AG">}
from /Users/josh/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.2.8/lib/action_dispatch/routing/route_set.rb:532:in `raise_routing_error'

Why doesn’t this work? What did I forget?

Thanks a lot for help,
Josh

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T05:40:51+00:00Added an answer on June 14, 2026 at 5:40 am

    A co-worker A looked into it, and decided that I shouldn’t put (:locale) into brackets. Another co-worker B mentioned, that he put it into brackets so that our tests work, where we do not want to specify the locale explicitly when calling an url helper method.

    Co-worker A mentioned, that the application itself falls back to the default_url_options method mentioned above, when an url helper method is called without locale. This is great, because except the root_path, we always want an explicit language set.

    In tests though, the default_url_options method is ignored (I’m not sure whether this is a bug or a feature, haha). So one has to do some workarounds:

    # Fixes the missing default locale problem in request specs.
    # See http://www.ruby-forum.com/topic/3448797
    class ActionView::TestCase::TestController
      def default_url_options(options={})
        { :locale => I18n.default_locale }
      end
    end
    
    class ActionDispatch::Routing::RouteSet
      def default_url_options(options={})
        { :locale => I18n.default_locale }
      end
    end
    
    # Fixes the missing default locale problem in controller specs
    # See http://www.ruby-forum.com/topic/3448797#1041659
    class ActionController::TestCase
      module Behavior
        def process_with_default_locale(action, parameters = nil, session = nil, flash = nil, http_method = 'GET')
          parameters = { :locale => I18n.default_locale }.merge( parameters || {} )
          process_without_default_locale(action, parameters, session, flash, http_method)
        end
        alias_method_chain :process, :default_locale
      end
    end
    
    module ActionDispatch::Assertions::RoutingAssertions
      def assert_recognizes_with_default_locale(expected_options, path, extras = {}, message=nil)
        expected_options = { :locale => I18n.default_locale.to_s }.merge(expected_options || {} )
        assert_recognizes_without_default_locale(expected_options, path, extras, message)
      end
      alias_method_chain :assert_recognizes, :default_locale
    end
    

    Put this into your spec_helper.rb file, and you’re ready to go with your controller and request specs! 🙂

    Still, in the console, this doesn’t seem to do the trick:

    $ app.user_path User.first
    ActionController::RoutingError: No route matches...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
This could be a duplicate question, but I have no idea what search terms
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I know there's a lot of other questions out there that deal with this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.