我有这个方法,在rake任务之后应该将我的数据保存到模型中,我试图一次更新2列,这不应该是个问题
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
在这种情况下,只有客队将保存,但是如果我这样做
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
然后只有主队才能保存。
我已经尝试了@ model.errors.full_messages但是为nil类获取了未定义的方法,所以没有?
我正在尝试调试此问题但不确定我可以用什么来查找问题
以前有没有人经历过这个?让我疯了
修改
我可以从控制台手动更新字段,所以当我这样做时
Fixture.create(:away_team => "String")
它更新
由于
答案 0 :(得分:1)
当你使用#create!
时,如果它无法保存就应该抛出错误,这应该意味着你没有尝试保存任何东西(空数组)。
验证
get_away_fixtures
get_home_fixtures
看起来像你期望的那样。安装debugger
并在Fixture.destroy_all
之后添加。