I'm trying to import my database, which have Project
and Technology
models (project has many technologies). Each project should have at least 1 technology. I use rails_admin_import gem for this task. As far as I understand, during project import gem is supposed to find associations of the model (technologies in my case) and connect them to model if they exist.
Everything is fine when I import technologies, but as soon as I'm importing projects, I receive this error for each of the projects:
Failed to create Project_1: Technologies minimum allowed: 1
I tried to import projects before importing technologies and after that, added to both of them mapping key, but nothing changed:
config.model 'Project' do
import do
mapping_key :name
include_all_fields
end
end
config.model 'Technology' do
import do
mapping_key :name
include_all_fields
end
end
Maybe anyone can help me and say what am I doing wrong?
UPD: The problem is that I exported data using default rails_admin export, which saves data in csv like that:
But rails_admin_import expects data in this format:
So I need to change my question. How should I configure rails_admin so that it would export data in a format accepted by rails_admin_import?
I found a way to do this, but probably not the best one.
I used before_import_associations
method of rails_admin_import to create needed technologies
key manually.
def before_import_associations(record)
record[:technologies] = record[:name_technologies].split(',')
end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.