【发布时间】:2015-03-12 14:24:04
【问题描述】:
我有一个模型FileType 的_form.html.haml 部分,我想在我的new.html.haml 和edit.html.haml 视图中呈现它。
= simple_form_for [:document_manager, file_type] do |f|
...
当我在 new 视图中渲染这个部分时,这是可行的,但是当我在 edit 视图中渲染它时,simple_form 尝试设置 id file_type 到 locale 参数如果我的路线。我的路线如下所示:
Rails.application.routes.draw do
scope '(:locale)', locale: locale: /#{I18n.available_locales.join('|')}/ do
namespace :document_manager do
resources :file_types, except: [:show]
end
end
end
对于 new 视图,路由 /en/document_manager/file_types 已生成,但当我尝试访问 edit 视图时出现此错误:
No route matches {
:action=>"update",
:controller=>"document_manager/file_types",
:format=>nil,
:id=>nil,
:locale=>#<FileType _id: 550198ca7462720388010000, user_file_id: nil, file_name: "...", description: "...">
} missing required keys: [:id]
如何更改为new和edit正确设置id和locale参数的表单?
更新:第一个可行的解决方案是删除 locale 范围并将语言存储在会话中,但对于 SEO,这将导致重复内容,因此更好的解决方案是有这样的网址:
- /zh/document_manager/file_types
- /fr/document_manager/file_types
- /de/document_manager/file_types
- ...
【问题讨论】:
标签: ruby-on-rails mongoid simple-form rails-i18n