Why rails app is redirecting unexpectedly instead of matching the route?

Posted by ruevaughn on Stack Overflow See other posts from Stack Overflow or by ruevaughn
Published on 2012-04-07T05:50:45Z Indexed on 2012/04/07 17:30 UTC
Read the original article Hit count: 237

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?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about rails-routing