Debugging why the create method does not save the model

I have this method, which, after the rake task has to save my data in the model, I try to update 2 columns at a time, which should not 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 case, only the guest 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 tried @ model.errors.full_messages, but got an undefined method for the nil class, so aren't there any?

I am trying to debug this problem, but I donโ€™t know what I can use to find the problem.

Has anyone experienced this before? Driving me crazy

EDIT

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

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

he updates thin

thank

0
methods debugging activerecord ruby-on-rails-3 rake-task
Mar 13 '13 at 13:17
source share
1 answer

How do you use #create! , it should give an error if it could not be saved, which should mean that you are not trying to save anything (an empty array).

Make sure that

 get_away_fixtures get_home_fixtures 

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

+1
Mar 13 '13 at 14:35
source share
โ€” -



All Articles