【发布时间】:2018-02-01 15:12:45
【问题描述】:
Contentful 文档非常少。我想更新一个条目上的一个字段,该字段是指向另一个条目的链接(“参考”是他们在 CMS UI 中的称呼)。
在使用 Contentful Management API 时,有人知道他们想要什么格式吗?
type ||= @mgmt.content_types.find(
ENV['CONTENTFUL_SPACE_ID'], 'comments'
)
entry = type.entries.create(
title: params[:title],
article: params[:article]
)
其中:article 是字符串形式的条目ID。这返回:
undefined method `id' for "7L4IpEtsdffds8EsmoWMGIgy":String
Extracted source (around line #74):
#72 case field.type
#73 when ContentType::LINK then
*74 { sys: { type: field.type, linkType: field.link_type, id: attribute.id } } if attribute
#75 when ContentType::ARRAY then
#76 parse_fields_array(attribute)
#77 when ContentType::LOCATION then
我还尝试将params[:article] 替换为@client.entry(params[:article]),认为他们可能想要整个对象,但它返回相同的错误,只是它将相同的参数视为空字符串。
我也根据@DavidLitvak 的建议尝试过:
link = Contentful::Management::Link.new({
sys: {
type: 'Link',
linkType: 'Entry',
id: params[:article]
}
})
entry = type.entries.create(
title: params[:title],
article: link
)
虽然这不会引发错误,但在填充标题字段时,文章字段会显示没有条目。
另外请注意,我使用的是 Ruby gem:contentful-management。
【问题讨论】:
标签: ruby contentful