调试为什么创建方法不保存到模型

调试为什么创建方法不保存到模型

本文介绍了调试为什么创建方法不保存到模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的方法,rake任务后,应我的数据保存到模型中,我试图更新2列的时间,这不应该是一个问题。

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.

我已经试过@ model.errors.full_messages但得到了一个未定义的方法无类,所以有没有?

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

修改

我可以从控制台手动更新的领域,所以当我做

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

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

它更新精

感谢

推荐答案

当你使用 #create!,它应该抛出一个错误,如果它无法保存,这应该意味着你不试图保存任何东西(空数组)。

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).

确认

get_away_fixtures
get_home_fixtures

看你期望他们。安装调试和后 Fixture.destroy_all 添加。

这篇关于调试为什么创建方法不保存到模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 10:26