我有一个应用程序(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) 我有一个带有安装引擎的项目.到目前为止,除了"更新"功能外,一切都按预期工作.引擎控制器是通过脚手架创建的,一切看起来都像我期望的那样.索引,显示,编辑,删除所有按预期工作,以及关联的前后过滤操作.
但是,Update会引发以下异常:
屏幕:
NoMethodError in MeetmeManagerPlugin::ConferenceRoomsController#update
private method `update' called for #<MeetmeManagerPlugin::ConferenceRoom:0x007fe8ac24a080>
Run Code Online (Sandbox Code Playgroud)
安慰:
NoMethodError (private method `update' called for #<MeetmeManagerPlugin::ConferenceRoom:0x007fe8ac24a080>):
activemodel (3.2.13) lib/active_model/attribute_methods.rb:404:in `method_missing'
activerecord (3.2.13) lib/active_record/attribute_methods.rb:149:in `method_missing'
/Volumes/MacTheCrypt 1/Project Work/jkl5_projects/meetme_manager_plugin/app/controllers/meetme_manager_plugin/conference_rooms_controller.rb:57:in `update'
actionpack (3.2.13) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.2.13) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.2.13) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.2.13) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
Run Code Online (Sandbox Code Playgroud)
控制器中的实际代码如下:
def update
if @conference_room.update(conference_room_params)
redirect_to @conference_room, notice: 'Conference room was successfully updated.'
else
render action: 'edit'
end
end
Run Code Online (Sandbox Code Playgroud)
令人窒息的是"@ conference_room.update(conference_room_params)".
相当多的网络搜索尚未对此有所了解,所以我认为这里有人可能会有一个建议.在此先感谢,如果您需要我的任何进一步的信息,请告诉我.