對不起,反應遲緩。 最近,我爲gem wiki添加了一個新示例,它與您的問題非常相似。 它可以使用自定義的before_batch_import
鉤master
分支
下一個例子來解決演示瞭如何動態地執行插入查詢之前解決從作者的姓名和更改CSV值AUTHOR_ID值。
ActiveAdmin.register Post do
active_admin_import validate: true,
headers_rewrites: { :'Author name' => :author_id },
before_batch_import: ->(importer) {
authors_names = importer.values_at(:author_id)
# replacing author name with author id
authors = Author.where(name: authors_names).pluck(:name, :id)
options = Hash[*authors.flatten] # #{"Jane" => 2, "John" => 1}
importer.batch_replace(:author_id, options) #replacing "Jane" with 1, etc
}
end
太好了!就是這樣。 – 2015-01-23 21:26:48