Post:: Model
class Post < ActiveRecord::Base
attr_accessible :body, :name, :no, :num
end
<标题>职位。Yml under (test/fixtures/)one:
name: MyString
body: MyString
no: 1
num: 2
在运行rake test:units
时,将生成以下堆栈跟踪
Error:
test_Post_for_correct_attributes(PostTest):
ActiveRecord::StatementInvalid: SQLite3::SQLException: table posts has no column named false: INSERT INTO "posts" ("name", "body", "false", "num", "created_at", "updated_at", "id") VALUES ('MyString', 'MyString', 1, 2, '2012-12-26 10:24:36', '2012-12-26 10:24:36', 980190962)
现在,这里-表字段'no'已被转换为'false'。(这似乎是一个问题,因为它被解释为FALSE,而不是一个对象变量)
如何将变量从yaml转换为对象的错误?
Rails版本Rails 3.2.9
和Ruby ruby 1.9.3p194
这对我来说似乎是一个bug,因为Rails应该能够拾取它,特别是因为这是自动生成的。无论如何,作为临时锻炼,您可以使用:
one:
name: MyString
body: MyString
"no": 1
num: 2