Answer the question
In order to leave comments, you need to log in
How is data import done in Rails?
There is a music table, it stores data in the form
music
- artist_id
- album_id
- title
- length
- picture_id
- uploader_id
и т.д.
Артист,Альбом,Название,Длина, и т.д
Answer the question
In order to leave comments, you need to log in
For parsing, CSV from the standard ruby library has always been enough for me.
In a similar situation, I did this:
I downloaded all csv files into memory, prepared indexes for linking (in Hash) and then using the create, build and save methods created objects by linking them.
Example:
transaction do
albums = {}
album_csv.each do |line|
raise "errrrr" if albums.has_key? line.title
albums[line.title] = Album.create!(title: line.title)
end
artist_csv.each do |line|
artist = Artist.new(title: line.title)
artist.album = albums[line.album] or fail "no album: #{line.album}"
artist.save!
end
end
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question