Home > Mobile >  Is there a way to assign a list of numbered variables in a seed file in ruby
Is there a way to assign a list of numbered variables in a seed file in ruby

Time:03-03

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

CodePudding user response:

Perhaps like this:

(13..24).each do |i|
  list_X = List.create(title: "list #{i}", #... )
end

CodePudding user response:

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"
  •  Tags:  
  • ruby
  • Related