我添加了I18n到我正在使用Devise的RoR應用程序,如果我嘗試執行密碼重設,我現在正在收到錯誤。錯誤是:Devise和I18n - 重置密碼路由問題
Routing Error
No route matches {:action=>"edit", :controller=>"devise/passwords", :reset_password_token=>"uMopWesaxczNn2cdePUQ"}
我該如何正確設置我的Devise路由到I18n帳戶?
的routes.rb
scope ":locale", locale: /#{I18n.available_locales.join("|")}/ do
devise_for :users, path_names: {sign_in: "login", sign_out: "logout"},
controllers: {omniauth_callbacks: "omniauth_callbacks"}
root to: 'static_pages#home'
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
哇,謝謝!令人驚訝的是,一組缺失的括號給我帶來了很多麻煩。 – diasks2 2012-08-13 12:42:02
我很高興它確實有幫助!此功能在Rail i18n文檔指南中有記錄,但有一點難以注意:) – 2012-08-13 14:32:16
這肯定有助於解決問題 - 但這不會導致另一個問題 - 即重複的URL?如果使用括號,則所有語言環境都不允許使用。因此,可以通過多個Url訪問相同的內容.... – 2014-03-29 05:08:41