Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

336
Visualizações
Is there a way to assign a list of numbered variables in a seed file in ruby

I'm trying to create 12 instances of the object list in a seed file, where:

12.times do |i|
list_X = List.create(title: "list #{i +1}" description: Faker::Hipster.paragraph, order_id: order_1.id, user_id: user_1.id)

Problem is that I can't find a way to update X so that it changes on each iteration. I'd like to update it with whatever value i is + 1

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Perhaps like this:

(13..24).each do |i|
  list_X = List.create(title: "list #{i}", #... )
end
over 4 years ago · Santiago Trujillo Relatório

0

Your code seems like it should be working

12.times do |i|
 p  "list #{i +1}"
end

Results: 
"list 1"
"list 2"
"list 3"
"list 4"
"list 5"
"list 6"
"list 7"
"list 8"
"list 9"
"list 10"
"list 11"
"list 12"
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda