RAILS File Seed Wheel, but Does Not Save The Data in the Database

0

I am creating a seeds file to popular my database, this file is responsible for popular Grupos(model :grupo) that runs without problem and also popular TipoAtividade(model :tipo_atividade) , which belongs to the group. >

WhenIrunrakedb:seeditrunsnormallyandgeneratesthegroupsandappearstohavegeneratedthetypestoo,justbelowthecodeoftheseedsfile.

ButwhenIlookatthedatabase,thisiswhatappears.

Itcreatesarowinthedatabase,butdoesnotsavethedatainthenamecolumnsandthegrupo(grupo_id)reference. Iwouldliketoknowwhatishappening,asIhaveresearchedtheinternetandfoundnothingthatwasveryclearaboutthisproblem.Igottoseesomethingof"protected_attributes", but the gem conflicts with certain versions of rails and / or bundler, I could not identify.

If the question is not clear, just ask me to edit it.

    
asked by anonymous 22.11.2018 / 10:30

1 answer

1

In the example above you have created 3 groups. The Group class has a has_many :tipo_atividades relationship

You should have the instance of a Grupo example:

# pegando o útimo grupo criado
grupo3 = Grupo.last
grupo3.tipo_atividades.create(nome: 'Palestra')

or

# pegando os últimos 3 grupos criados
Grupo.last(3).each do |grupo|
  grupo.tipo_atividades.create(nome: 'Palestra')
end

Using the has_many method

    
23.11.2018 / 00:20