2
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
我也試圖與@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
。
這成功地生成鏈接散列並將該情況下,這個時間,所以沒有任何錯誤。但它仍不會在CMS中創建鏈接。該字段仍然是空的。 – JLF
您可以通過https://support.contentful.com/hc/en-us打開支持請求。在那裏我們可以更好地幫助你解決你的問題。 –