Rails : i18n : unexpected redirections

In my app, I have different User types like VehicleOwner , GarageOwner, Admin and unidentified/unauthenticated. I wanted to implement localization for English and Finnish. I was successful, but suddenly all my old URLs stopped working; when I tried to access the old URLs I was redirected to login page, and the login page was also not loading – stuck on infinite redirection loop.

# Initial implementation
unauthenticated :user do
  get '/:locale' => 'pages#home'
  root 'pages#home', page: :home
end

authenticate :user, ->(user) { user.vehicle_owner? } do
  get '/:locale' => 'vehicle_owners/quote_requests#index'
  root 'vehicle_owners/quote_requests#index'
end

authenticate :user, ->(user) { user.garage_owner? } do
  get '/:locale' => 'garage_owners/quote_requests#index'
  root 'garage_owners/quote_requests#index'
end

Solution

unauthenticated :user do
  get '/:locale' => 'pages#home', locale: /en|fi/
  root 'pages#home', page: :home
end

authenticate :user, ->(user) { user.vehicle_owner? } do
  get '/:locale' => 'vehicle_owners/quote_requests#index', locale: /en|fi/ # because iisifix.fi/en should be addressed
  root 'vehicle_owners/quote_requests#index'
end

authenticate :user, ->(user) { user.garage_owner? } do
  get '/:locale' => 'garage_owners/quote_requests#index', locale: /en|fi/
  root 'garage_owners/quote_requests#index'
end

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s