【问题标题】:activeadmin-globalize does not update recordsactiveadmin-globalize 不更新记录
【发布时间】:2014-05-08 16:28:15
【问题描述】:

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

【问题讨论】:

    标签: ruby-on-rails localization activeadmin globalize3


    【解决方案1】:

    您必须在 permit_params 处将 :id 添加到 translations_attributes:

    permit_params :title, :text, translations_attributes: [:id, :title, :text, :locale]
    

    【讨论】:

    • 谢谢。你太棒了!
    • 能否请您引导我找到您从中获得该信息的任何来源?这真的很有帮助。
    • 嗯,翻译是独立的实体。如果您省略了他们的 id,rails 会将他们视为新记录。
    • 就我而言,这只发生在生产中
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-25
    • 2018-06-09
    相关资源
    最近更新 更多