Ruby on rails 4 在rails中创建或更新记录
我正在从外部数据库读取数据。 因此,我这样做是为了在代码第一次运行时创建数据库。 我只粘贴创建部分。从外部数据库读取的代码是我不允许公开的Ruby on rails 4 在rails中创建或更新记录,ruby-on-rails-4,updating,Ruby On Rails 4,Updating,我正在从外部数据库读取数据。 因此,我这样做是为了在代码第一次运行时创建数据库。 我只粘贴创建部分。从外部数据库读取的代码是我不允许公开的 Collection.create( name: xxxxxx, title: xxxxxx, description: xxxxx, date: xxxxx, collectie: xxxxx, colors
Collection.create(
name: xxxxxx,
title: xxxxxx,
description: xxxxx,
date: xxxxx,
collectie: xxxxx,
colors: xxxxxx,
small_image: xxxxxx,
)
我怎样才能更改它,以便下次在数据更改的地方只更新记录,这样我就不必执行rake:drop和rake db:migrate,然后执行这个rake任务,如果我想获得最新的数据
编辑1:我试图更改以查找或创建,但后来我看到了很多错误
item = Collection.where(
name: xxxxxx,
title: xxxxxx,
description: xxxxx,
date: xxxxx,
collectie: xxxxx,
colors: xxxxxx,
small_image: xxxxxx
).first_or_create
然后,您可以使用item.update操作项目。如果需要,请更新。谢谢,我尝试过,但看到了此错误消息;看起来您的模型有问题。集合是否与数据库中的列匹配?