由于不推荐使用ActionController :: Base#default_url_options,我想知道如何在rails3中设置默认的url选项.默认URL选项不是静态的,而是依赖于当前请求.
http://apidock.com/rails/ActionController/Base/default_url_options
谢谢,科林
我有一个应用程序(my_test_app),内置了i18n支持.目前,有两种语言文件可用,FR&EN,如果我在它们之间来回切换,一切正常,因为我希望看到非引擎功能,如用户索引/显示/编辑/删除(ISED)选项.
在my_test_app中,我安装了一个Rails引擎(my_engine),它有一个控制器和模型集(engine_job).所以,一个可行的URL应该是
http://0.0.0.0:3000/fr/my_engine/engine_job
Run Code Online (Sandbox Code Playgroud)
然而,无论我选择何种语言,它总是出现在EN中.检查参数显示:
--- !ruby/hash:ActiveSupport::HashWithIndifferentAccess
locale: fr
action: index
controller: my_engine/engine_job
Run Code Online (Sandbox Code Playgroud)
然而,所选择的翻译是EN.
my_test_app route.rb:
MyTestApp::Application.routes.draw do
scope "(:locale)", locale: /#{I18n.available_locales.join("|")}/ do
mount MyEngine::Engine, at: "/my_engine"
end # scope locale
match '*path', to: redirect("/#{I18n.default_locale}/%{path}"), constraints: lambda { |req| !req.path.starts_with? "/#{I18n.default_locale}/" and !req.path == "/#{I18n.default_locale}/"}
match '', to: redirect("/#{I18n.default_locale}/")
end
Run Code Online (Sandbox Code Playgroud)
my_engine route.rb:
MyEngine::Engine.routes.draw do
resources :my_jobs
end
Run Code Online (Sandbox Code Playgroud)
耙路线:
my_engine (/:locale)/my_engine MyEngine::Engine {:locale=>/en|fr/}
/*path(.:format) :controller#:action
/ :controller#:action
users GET (/:locale)/users(.:format) users#index {:locale=>/en|fr/}
POST (/:locale)/users(.:format) users#create {:locale=>/en|fr/}
new_user GET (/:locale)/users/new(.:format) users#new {:locale=>/en|fr/}
edit_user …Run Code Online (Sandbox Code Playgroud) rails-i18n ×1