ruby on rails
I'm trying to import a CSV for a model that has a few acts-as-taggable-on properties. The tags are comma-separated, so I can write a basic rake task to import a CSV like this
CSV.foreach(filename, :headers => true) do |row|
Post.create!({
:title => row[0],
:description => row[1],
:body => row[2],
:location_list => row[3].split(','),
:topic_list => row[4].split(',')
})
end
But I'm trying to do this with Active Admin which has a gem already for bulk CSV imports - https://github.com/activeadmin-plugins/active_admin_import
The gem is handling mapping the columns in the database, but my CSV with the comma separated tags for the last 2 columns won't work because there is no "location_list" or "topic_list" column in the Post table since those are in separate tables and managed by the acts-as-taggable-on gem.
I see there are ways to overwrite the before_batch_import
and after_batch_import
, but is there a way to replace the actual batch_import process so it can correctly import the tags?
上一篇: 充当宝石上的标签
下一篇: 红宝石在轨道上