1
I have following table news :
create_table "noticia", force: true do |t|
t.integer "conteudo_id"
t.integer "entidade_id"
t.integer "imagem_id"
t.string "texto"
t.datetime "created_at"
t.datetime "updated_at"
end
and I have the following a. csv file containing these fields in the following format:
Texto_post, url image
I would appreciate a help on how to read the file and also if necessary it is possible to change the layout of the contents of the file.
table name in Rails is plural, "news"
– Felipe Bergamo
In this case . csv doesn’t have all the data to create the object, right? how will you do with relationships?
– Felipe Bergamo
Conteudo.create(titulo: data[0])
 conteudo_id = Conteudo.order("created_at").last.id
 Imagem.create(imagem_url: data[2])
 imagem_id = Imagem.order("created_at").last.id
 Noticium.create(conteudo_id: conteudo_id,entidade_id: data[1], imagem_id: imagem_id, texto: data[3])
– CarlosMachado