Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 工厂女孩模型&x27;s id=>;无_Ruby On Rails_Ruby_Ruby On Rails 4_Factory Bot - Fatal编程技术网

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控制台中使用相同的属性是否能够创建实例?