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

  • Home
  • SEARCH
  • 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 521143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:13:09+00:00 2026-05-13T08:13:09+00:00

In my application_controller, I have the following set to include the locale with all

  • 0

In my application_controller, I have the following set to include the locale with all paths generated by url_for:

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

My resource routes then have a :path_prefix = “/:locale”

Works fine on the site.

But when it comes to my functional tests, the :locale is not passed with the generated urls, and therefore they all fail. I can get around it by adding the locale to the url in my tests, like so:

  get :new, :locale => 'en'

But I don’t want to have to manually add the locale to every functional test.

I tried adding the default_url_options def above to test_helper, but it seems to have no effect.

Is there any way I can change the default_url_options to include the locale for all my tests?

Thanks.

  • 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-05-13T08:13:10+00:00Added an answer on May 13, 2026 at 8:13 am

    Looking through how the controller test case generates the url there doesn’t seem to be a direct way to have it use the defualt_url_options. The main block that actually does the url creationg (in the tests) looks like this (http://github.com/rails/rails/blob/master/actionpack/lib/action_controller/test_case.rb):

    private
      def build_request_uri(action, parameters)
        unless @request.env['REQUEST_URI']
          options = @controller.__send__(:rewrite_options, parameters)
          options.update(:only_path => true, :action => action)
    
          url = ActionController::UrlRewriter.new(@request, parameters)
          @request.request_uri = url.rewrite(options)
        end
      end
    

    This gets called by the process method which is in turn called by the get, post, head, or put methods. One way to maybe get what you are looking for might be to alias_chain the process method.

    class ActionController::TestCase
      def process_with_default_locale(action, parameters = nil, session = nil, flash = nil, http_method = 'GET')
        parameters = {:locale=>'en'}.merge(parameters||{})
        process_without_default_locale(action, parameters, session, flash, http_method)
      end
      alias_method_chain :process, :default_locale
    end
    

    You’ll want to put that into your test helper, outside of the TestCase class I think. Let me know how it works for you, I haven’t really tested it out so we’ll see.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 264k
  • Answers 264k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The following code ought to work: procedure NilAllEventHandlers(myObject: TObject); var… May 13, 2026 at 12:16 pm
  • Editorial Team
    Editorial Team added an answer Properties look like fields but they are methods. This has… May 13, 2026 at 12:16 pm
  • Editorial Team
    Editorial Team added an answer You cannot get the pressure from the SDK nor undocumented… May 13, 2026 at 12:16 pm

Related Questions

I have the following code in a strongly-typed View in my application: <td> <label
I've set up a new Rails 2.3.2 app and added the Basecamp API ruby
I'm having a difficult time wrapping my head around loading views with Interface Builder
Sorry if this as already been asked. I am currently working on a small
I have several before_filters defined in my application controller to handle requests I don't

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.