0

I have this method which after a rake task should save my data to the model, I am trying to update 2 columns at a time, which shouldnt be a problem

  def update_fixtures #rake task method
   Fixture.destroy_all
   get_home_fixtures.each {|home| Fixture.create!(home_team: home )}
   get_away_fixtures.each {|away| Fixture.create!(away_team: away )}
  end

In this instance only the away team will save, however if i do this

  def update_fixtures #rake task method
     Fixture.destroy_all
     get_away_fixtures.each {|away| Fixture.create!(away_team: away )}
     get_home_fixtures.each {|home| Fixture.create!(home_team: home )}
  end

Then only the home team will save.

I have tried @model.errors.full_messages but get undefined method for nil class, so there are none?

I am trying to debug this issue but unsure on what i can use to find the problem

Has anyone experienced this before? Driving me insane

EDIT

I can update the field manually from the console, so when I do

Fixture.create(:away_team => "String")

it updates fine

Thanks

Richlewis
  • 15,070
  • 37
  • 122
  • 283

1 Answers1

1

As you're using #create!, it should throw an error if it failed to save, which should mean that you're not trying to save anything (empty array).

Verify that

get_away_fixtures
get_home_fixtures

look as you expect them to. Install debugger and add it after Fixture.destroy_all.

Frans
  • 1,389
  • 2
  • 16
  • 28
  • where will the error be produced, as you say create! should throw an error – Richlewis Mar 13 '13 at 14:48
  • When the method is called. You're running some rake task that calls that method, right? When that task calls the method the error should abort the task and show a stack trace. – Frans Mar 13 '13 at 14:58
  • ah right, no it doesn't do that, it completes the rake task and fills in either the home team or away team info, dependent upon which way around i have my methods, ie get_home_fixtures – Richlewis Mar 13 '13 at 15:00
  • I'd still recommend throwing the debugger in there, checking what get_away_fixtures and get_home_fixtures contains and running the rest of the method manually. – Frans Mar 13 '13 at 15:15
  • Ive accepted answer as debugger is a nice tool, with regards as to why both methods where not writing to the model, its because I have found that one create was overridding the other, which makes sense now – Richlewis Mar 14 '13 at 08:45