我有一个名为“documents”的表,它有附件(通过回形针创业板),我想为这个附件添加翻译(通过全球化的gem),以便在Activeadmin中使用。因此,一旦我在active admin中打开文档页面,我想添加两个或更多的文档翻译,但对于相同的模型(相同的模型id,但只更改区域设置)。
文档模型的架构创建表DB表是:
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。
发布于 2016-06-26 07:27:05
最后,我已经通过从documents表中删除附件'doc‘来解决这个问题,然后使用globalize 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对于文档模型,最后通过active admin表单访问它(创建/更新):
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
endhttps://stackoverflow.com/questions/37678581
复制相似问题