错误:PG::UndefinedColumn。自定义字段未创建列

我暂时找不到 TopicCustomField(但我已经告诉过你该去哪里找了!:wink:)

这是这个:

[4] pry(main)> CategoryCustomField.last
=> #<CategoryCustomField:0x000055be74a00bd0
 id: 2,
 category_id: 8,
 name: "enable_accepted_answers",
 value: "true",
 created_at: Mon, 26 Apr 2021 15:45:07.862617000 UTC +00:00,
 updated_at: Mon, 26 Apr 2021 15:45:07.862617000 UTC +00:00>

所以类似这样:

tcf = TopicCustomField.where(name: 'fun_level', value: 'super-duper-fun')

然后你可以从 tcf 中获取 topic_id 等信息(它是一个包含所有匹配项的数组)。如果你知道 topic_id,可以使用 TopicCustomField.find_by(<这三个能确保唯一性的条件>)。