Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.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 ActiveRecord::Fixture::FormatError:解析时发生YAML错误_Ruby On Rails_Ruby_Fixture - Fatal编程技术网

Ruby on rails ActiveRecord::Fixture::FormatError:解析时发生YAML错误

Ruby on rails ActiveRecord::Fixture::FormatError:解析时发生YAML错误,ruby-on-rails,ruby,fixture,Ruby On Rails,Ruby,Fixture,我正在尝试在ruby上创建我的第一个应用程序的一个示例。。。 这是我的测试文件 require File.dirname(__FILE__) + '/../test_helper' class SupplierTest < ActiveSupport::TestCase fixtures :suppliers def test_name supplier=Supplier.create(:name => 'juan'

我正在尝试在ruby上创建我的第一个应用程序的一个示例。。。 这是我的测试文件

   require File.dirname(__FILE__) + '/../test_helper'

   class SupplierTest < ActiveSupport::TestCase
        fixtures :suppliers
        def test_name
           supplier=Supplier.create(:name => 'juan' , :province => nil)
           assert_equal 'juan' , supplier.get_name
        end
   end
结果是

    Psych::SyntaxError: (<unknown>): could not find expected ':' while scanning    a  simple key at line 8 column 1
Psych::SyntaxError:():在扫描第8行第1列的简单键时找不到预期的“:”

YAML需要在
和值之间留一个空格,因此请尝试将设备更新为:

juan: 
  id: 1
  name: juan
  province: 

(在省中写入
nil
将导致值
为“nil”
。保留为空将导致值为真
nil
我已更改了添加空格的装置,但现在显示ActiveRecord::fixture::FormatError:再次检查YAML的格式是否正确,如果正确,检查这是否是您的问题:使用任何在线或离线工具检查YAML语法和正确性。例如:yaml-online-parser.appspot.com要在yaml中显式表达Ruby的
nil
,请使用。
juan: 
  id: 1
  name: juan
  province: