Ruby on rails 工厂女孩模型&x27;s id=>;无
我有一个模型:Ruby on rails 工厂女孩模型&x27;s id=>;无,ruby-on-rails,ruby,ruby-on-rails-4,factory-bot,Ruby On Rails,Ruby,Ruby On Rails 4,Factory Bot,我有一个模型: class CreateStores < ActiveRecord::Migration def change create_table :stores do |t| t.integer :admin_id t.string :name t.string :subdomain t.string :linked_domain t.timestamps end end end class C
class CreateStores < ActiveRecord::Migration
def change
create_table :stores do |t|
t.integer :admin_id
t.string :name
t.string :subdomain
t.string :linked_domain
t.timestamps
end
end
end
class CreateStores
和测试:
require 'test_helper'
class Api::Be::UsersControllerTest < ActionController::TestCase
setup do
@admin = FactoryGirl.create :admin
@store = FactoryGirl.create :store
@store.ug_default = UgDefault.new
@store.save
Rails::logger.debug "HERE: #{@store.id}"
@customer = FactoryGirl.create :customer
@customer.userable_id = @store.id
@customer.save
end
需要“测试助手”
类Api::Be::UsersControllerTest
在日志中,我看到
@store.id
等于零。有什么问题吗?可能无法保存。使用记录器,如果模型上存在任何错误,则输出:
Rails.logger.debug "#{@store.errors.inspect}"
在输出的末尾查找消息。您的模型如何?#哪里没有错误,对吗?正确,消息哈希为空。在模型上保存回调之前,是否返回false?在rails控制台中使用相同的属性是否能够创建实例?