Ruby on rails 4 将FactoryGirl与所属对象一起使用的语法
当使用FactoryGirl与Ruby on rails 4 将FactoryGirl与所属对象一起使用的语法,ruby-on-rails-4,rspec,factory-bot,Ruby On Rails 4,Rspec,Factory Bot,当使用FactoryGirl与所属关系时,我无法正确使用语法 我有一个模式,包括: create_table "region_classifiers", force: true do |t| t.string "name" t.boolean "is_default" t.datetime "created_at" t.datetime "updated_at" end create_table "regions", force: true do |t|
所属关系时,我无法正确使用语法
我有一个模式,包括:
create_table "region_classifiers", force: true do |t|
t.string "name"
t.boolean "is_default"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "regions", force: true do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "region_classifier_id"
end
我的地区
型号是:
class Region < ActiveRecord::Base
belongs_to :region_classifier
end
我可以用它创建一个区域
Region.create(name: 'Bar', region_classifier: RegionClassifier.first)
但是当我调用FactoryGirl.create(:region)
时,我得到一个错误:
can't write unknown attribute `region_classifier_id' (ActiveModel::MissingAttributeError)
我大概是误读了FactoryGirl文档,但我如何才能让它创建区域呢
编辑:
哦,没关系。我需要让事情继续发展,所以我回滚了数据库,撤消了对区域的一系列更改,销毁了脚手架,删除了迁移,然后根据我想要的区域的当前版本创建了一个新的脚手架。它现在起作用了,所以很明显我的一次迁移没有达到我想要的效果 你准备好测试数据库了吗?(rake测试:准备
)是。我已经运行了rake:test:再次准备以防万一,但没有变化。
can't write unknown attribute `region_classifier_id' (ActiveModel::MissingAttributeError)