2
在我的Ruby on Rails應用程序中,我設置了OAuth以使用omniauth gem工作。一切工作順利;然而,一旦我將I18n添加到應用程序中,我無法使其工作。具體來說,問題在於回調。如何調整我的routes.rb代碼以正確處理使用I18n的回調?在Ruby on Rails中使用I18n設置OAuth回調
的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
問題的確切性質是什麼?你能添加更多關於這個問題的細節嗎?例如錯誤,未發生的事情等等 – 2012-08-06 23:30:53