如何为文档添加翻译



我有一个名为"文档"的表,其中包含附件(通过回形针 gem),我想为此附件(通过全球化 gem)添加翻译以在 Activeadmin 中使用。因此,一旦我在活动管理员中打开文档页面,我想为同一模型添加文档的两个或多个翻译(相同的模型 ID 但只有区域设置更改)。

文档模型的架构创建表数据库表为:

create_table "documents", force: :cascade do |t|
    t.datetime "created_at",       null: false
    t.datetime "updated_at",       null: false
    t.string   "doc_file_name"
    t.string   "doc_content_type"
    t.integer  "doc_file_size"
    t.datetime "doc_updated_at"
    t.integer  "model_id"
  end

数据库是Postgres。

最后,我通过从文档表中删除附件"doc"来解决它,然后使用全球化 gem Document.create_translation_table!为文档创建翻译表并添加:

has_many :docs
 class Translation
    belongs_to :document
    has_attached_file :doc, MODEL_DOCUMENTS_STORAGE_OPTIONS
    validates_attachment_content_type :doc, content_type: ['application/pdf']
  end

到文档模型,然后最终通过活动管理表单访问它(创建/更新):

form :html => { :enctype => 'multipart/form-data' } do |f|
    f.inputs 'Details' do
      f.translated_inputs 'ignored title', switch_locale: false do |t|
        t.input :doc, :as => :file
      end
    end
    actions
  end

最新更新