我正在使用 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 仍然看到第一个。