我正在使用 rails4、activeadmin、globalize 和 activeadmin-globalize。我创建了一个测试应用程序,但它无法正常工作。
我有一个模型类model.rb
class Post < ActiveRecord::Base
active_admin_translates :title, :text do
validates_presence_of :title
end
end
和适当的迁移
class CreatePosts < ActiveRecord::Migration
def up
create_table :posts do |t|
t.timestamps
end
Post.create_translation_table! title: :string, text: :text
end
def down
drop_table :posts
Post.drop_translation_table!
end
end
事件管理页面是这样配置的
ActiveAdmin.register Post do
permit_params :title, :text, translations_attributes: [:title, :text, :locale]
index do
translation_status
default_actions
end
form do |f|
f.translated_inputs 'Translated fields', switch_locale: false do |t|
t.input :title
t.input :text
end
f.actions
end
end
当我在 ActiveAdmin 中创建新记录时,一切正常,本地化也被保存。问题是当我尝试编辑和保存该记录时,没有任何改变。
谁能告诉我我做错了什么?是否有任何我可以下载并亲自尝试的工作示例解决方案?
更新:
我刚刚发现,每当我尝试更新记录时,都会在翻译表中创建新的翻译记录元组。 ActiveAdmin 仍然看到第一个。
最佳答案
您必须在 permit_params 处将 :id 添加到 translations_attributes:
permit_params :title, :text, translations_attributes: [:id, :title, :text, :locale]
关于ruby-on-rails - activeadmin-globalize 不更新记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23547401/