内容丰富的文档相当稀疏。我想更新一个条目上的一个字段,该字段是指向另一个条目的链接("Reference“是他们在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我还尝试用@client.entry(params[:article])替换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。
发布于 2017-08-24 06:23:51
您需要发送的是引用文章的Link。
您可以这样做:
entry = type.entries.create(
title: params[:title],
article: Contentful::Management::Link.new({
sys: {
id: params[:article],
type: 'Link',
linkType: 'Entry'
}
})
)您可以在此处找到有关链接如何工作的更多信息:https://www.contentful.com/developers/docs/concepts/links/
https://stackoverflow.com/questions/45849717
复制相似问题