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 7768995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:03:40+00:00 2026-06-01T16:03:40+00:00

I asked this question earlier and thought it was fixed, but it’s not. Previous

  • 0

I asked this question earlier and thought it was fixed, but it’s not. Previous question here

My problem is I am trying to set my routes so that when I type in

localhost:3000/sites/admin

It should redirect to

localhost:3000/en/sites/admin

here is my routes.rb file

scope ":locale", locale: /#{I18n.available_locales.join("|")}/ do
  get "log_out" => "sessions#destroy", as: "log_out"
  get "log_in" => "sessions#new", as: "log_in"

  resources :sites, except: [:new, :edit, :index, :show, :update, :destroy, :create]   do
  collection do
    get :home
    get :about_us
    get :faq
    get :discounts
    get :services
    get :contact_us
    get :admin
    get :posts
  end
end
resources :users
resources :abouts
resources :sessions
resources :coupons
resources :monthly_posts
resources :reviews
resources :categories do
collection { post :sort }
resources :children, :controller => :categories, :only => [:index, :new, :create,   :new_subcategory]
end
resources :products do
  member do
    put :move_up
    put :move_down
  end 
end
resources :faqs do
  collection { post :sort }
end 
root :to => 'sites#home'
match "/savesort" => 'sites#savesort'

end

match '', to: redirect("/#{I18n.default_locale}")
match '*path', to: redirect("/#{I18n.default_locale}/%{path}")

But as of right now, it redirects to /en/en/en/en/en/en/en/en/en/en/sites/admin (adds en until browser complains).

Any thoughts why it keeps adding /en?

Edit:
The answer is great, thanks. Can you help me diagnose the root route?

root to: redirect("#{/#{I18n.default_locale}") # handles /

I know redirects is looking for something like

redirect("www.example.com")

So that leaves this part

#{/#{I18n.default_locale}

The #{ is using rubys string interpolation, right? i’m not sure what that { is doing though.

So then we have

/#{I18n.default_locale}

Which is also using string interpolation and to print out the value of I18n.default_locale?

Hopefully that makes sense, I really really appreciate the help, I am learning a lot.

Edit 2:

I changed the line from

root to: redirect("#{/#{I18n.default_locale}") # handles /

to

root to: redirect("/#{I18n.default_locale}") # handles /

But i’m not sure if thats right. Now i’m getting the error

uninitialized constant LocaleController

I know it’s getting the error from the root to: “locale#root”, but i thought the locale# would come from the scope.

I’ll continue playing with it and let you know any progress.

Here is a new link to my routes file https://gist.github.com/2332198

  • 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-01T16:03:41+00:00Added an answer on June 1, 2026 at 4:03 pm

    We meet again, ruevaughn. 🙂

    I created a test rails app and the following minimal example works for me:

    scope ":locale", locale: /#{I18n.available_locales.join("|")}/ do
      resources :sites do
        collection do
          get :admin
        end
      end
    
      root to: "locale#root" # handles /en/
      match "*path", to: "locale#not_found" # handles /en/fake/path/whatever
    end
    
    root to: redirect("/#{I18n.default_locale}") # handles /
    match '*path', to: redirect("/#{I18n.default_locale}/%{path}") # handles /not-a-locale/anything
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I asked this question earlier. I am intrigued by std::set but I have another
I asked this question a little earlier today but am not sure as to
I asked this question earlier and am now trying to explore the idea of
This question was asked earlier by someone else but never answered: MKAnnotation - Map
So I asked this question earlier: CSS box shadow not truly transparent? And I
I asked this question earlier but I was very vague and a lot of
I asked this question earlier but regarding another programming languages. Let's say I have
I asked this question earlier but I didn't express myself correctly. If I have
I asked this question earlier, but I'm missing one important thing. I have a
I have asked this question earlier today but I didn't provide enough information and

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.