In my Ruby on Rails app I have set up OAuth to work using the omniauth gem. Everything is working smoothly; however, I am having trouble getting it to work once I add I18n to the app. Specifically, the issue is with the callback. How can I adjust my routes.rb code to correctly handle the callback using I18n?
routes.rb
scope ":locale", locale: /#{I18n.available_locales.join("|")}/ do
resources :sessions, only: [:new, :create, :destroy]
root to: 'static_pages#home'
match 'auth/:provider/callback', to: 'sessions#create'
match 'auth/failure', to: redirect('/')
match 'signout', to: 'sessions#destroy', as: 'signout'
match '/signin', to: 'sessions#new'
match '/signout', to: 'sessions#destroy', via: :delete
end
match '*path', to: redirect {|params| "/#{I18n.default_locale}/#{CGI::unescape(params[:path])}" }, constraints: lambda { |req| !req.path.starts_with? "/#{I18n.default_locale}/" }
match '', to: redirect("/#{I18n.default_locale}")
application_controller.rb
before_filter :set_locale
def set_locale
I18n.locale = params[:locale] if params[:locale].present?
end
def default_url_options(options = {})
{locale: I18n.locale}
end
The answer to this question can be found here. The :locale needs to be in parentheses:
scope "(:locale)"