我创建了一个相当大的脚本来播种我的rails数据库。这是使用accepts_nested_attributes_for
帮助建立参数散列的一对多关系。该脚本工作好几天,但现在我得到以下错误。Rails 5 beta 3 ActiveRecord记录无效
的ActiveRecord :: RecordInvalid:验证失败:网站流量统计网站必须存在
我已经停用强参数,因为这是一个只读的应用。所有记录都从seeds.rb导入,因此我的控制器中没有创建,编辑新的方法 这是我的散列和散列数组。
{:company=>"Company A", :link=>"www.whatever.com",
`:website_statistics_attributes=>`
[{:statistic=>"Visitors", :today=>10, :this_week=>11.4, :last_week=>13.0},
{:statistic=>"Page Views", :today=>20, :this_week=>55, :last_week=>120}]}
唯一改变的是;我从github克隆了这个版本。我把我的产品版本推到github上,然后克隆到我的macbook上。该设置是相同的,所以我不知道这里发生了什么。
编辑:模型
class WebsiteStatistic < ApplicationRecord
belongs_to :websites
end
class Website < ApplicationRecord
has_many :website_statistics
accepts_nested_attributes_for :website_statistics
end
WORKS
是否有可能验证失败为您相关的'website_statistics'模式? –
显示两种型号定义 –
无验证。 – ctilley79