(雖然這裏討論了Blacklight引擎,但我相信這個問題實際上完全是關於Rails的。)'mount'附近的`scope'無效?
我想向我的Blacklight應用程序添加國際化。爲此,我
包裹在
config/routes.rb
一切都變成scope "(:locale)", locale: /en|ja/
和在
app/controllers/application_controller.rb
我加入before_action :set_locale
和推翻default_url_options
通過Rails i18n guide的建議。大多數情況下都可以工作,但有一件事我一直無法解決。
我所有的應用程序路徑都被正確映射,例如, http://www.example.com/en/catalog/12345
與(/:locale)/catalog/:id(.:format)
正確匹配,並通過{:id=>/[^\/]+(?=\.json|\.html|$|\/)/, :locale=>/en|ja/}
路由到catalog#show
)。 Devise的所有網址都很好。一切正常......除了mount
-ed Blacklight引擎。
顯然,Blacklight引擎不聽scope
。 rake routes
顯示:
Routes for Blacklight::Engine:
search_history GET /search_history(.:format) search_history#index
....
,而不是作爲(:locale)/search_history(.:format)
我希望。
我已經修改了黑光模板,使我得到一個語言選擇器指向當前頁面的日語和英語,但是當我瀏覽到search_history
,url_for
當與:locale
參數面臨突然拋出了。
爲什麼mount
忽略scope
?我如何解決我的問題(引擎路線也迴應:locale
)?
這裏是我的默認黑光燈產生的config/routes.rb
,與scope
修改:
Rails.application.routes.draw do
scope "(:locale)", locale: /en|ja/ do
mount Blacklight::Engine => '/'
root to: "catalog#index"
concern :searchable, Blacklight::Routes::Searchable.new
resource :catalog, only: [:index], as: 'catalog', path: '/catalog', controller: 'catalog', id: /[^\/]+(?=\.json|\.html|$|\/)/ do
concerns :searchable
end
devise_for :users
concern :exportable, Blacklight::Routes::Exportable.new
resources :solr_documents, only: [:show], path: '/catalog', controller: 'catalog', id: /[^\/]+(?=\.json|\.html|$|\/)/ do
concerns :exportable
end
resources :bookmarks, id: /[^\/]+(?=\.json|\.html|$|\/)/ do
concerns :exportable
collection do
delete 'clear'
end
end
end
end
TL;博士:scope
前綴我的所有航線,除由mount
路線。爲什麼,以及如何解決?