activeadmin-globalize不会更新记录

时间:2014-05-08 16:28:15

标签: ruby-on-rails localization activeadmin globalize3

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

1 个答案:

答案 0 :(得分:6)

您必须在permit_params:

添加:id到translations_attributes
permit_params :title, :text, translations_attributes: [:id, :title, :text, :locale]
相关问题