0

I am trying to create a runner script to build a model. The model is this:

class Day < ActiveRecord::Base
  has_many :slots
  attr_accessible  :available, :day_date, :venue
end

class Slot < ActiveRecord::Base
  belongs_to :day
end

I would like to make 100 blank Days with 9 Slots for each Day. This is runner script load_days.rb

Day.transaction do
  (1..100).each do |i|
   days = Date.today+i
   Day.create( :available => "Available", :venue => "Pitch_1", :day_date => days )
   (1..9).each to |j|
      hours = days.hours+j
      id = Day.id
      Slot.create ( :time_slot => hours , :day_id => id )
  end
 end
end

I am getting the following error: script/load_days.rb:8: syntax error, unexpected tASSOC, expecting tCOLON2 or '[' or '.' Slot.create ( :time_slot => hours , :day_id => id )

1 Answer 1

2

You are calling .id on the Day class instead of the Day object you created, this should work:

Day.transaction do
  (1..100).each do |i|
   days = Date.today+i
   day = Day.create( :available => "Available", :venue => "Pitch_1", :day_date => days )
   (1..9).each to |j|
      hours = days.hours+j
      id = day.id
      Slot.create ( :time_slot => hours , :day_id => id )
  end
 end
end
Sign up to request clarification or add additional context in comments.

2 Comments

there also seems to be the line (1..9).each to |j| which should be (1..9).each do |j|
that fixed it thanks. As well as Matthews comment i also had to fix hours = (time)+j.hours

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.