Ruby on rails 符合jsonapi.org的Rabl
我很难让rabl符合jsonapi.org规范。我在github上看到了关于这个()的wiki条目,但我不知道如何在rabl中获得多个根级节点,并且仍然可以使用集合。关于集合的wiki条目说这应该有效Ruby on rails 符合jsonapi.org的Rabl,ruby-on-rails,json,rabl,Ruby On Rails,Json,Rabl,我很难让rabl符合jsonapi.org规范。我在github上看到了关于这个()的wiki条目,但我不知道如何在rabl中获得多个根级节点,并且仍然可以使用集合。关于集合的wiki条目说这应该有效 collection [@post] => :posts attributes :id, :title child @post => :links do node(:author) { @post.author_id } node(:comments) { @post.co
collection [@post] => :posts
attributes :id, :title
child @post => :links do
node(:author) { @post.author_id }
node(:comments) { @post.comments_ids }
end
对于单根文档,它是这样做的,但只要我尝试向jsonapi.org规范中声明的文档根添加meta
或links
,这些节点就会附加到现有的集合节点。这是我的rabl_init.rb
require 'rabl'
Rabl.configure do |config|
config.cache_sources = Rails.env != 'development'
config.include_child_root = false
config.include_json_root = false
end
我希望json看起来像这样:
{
"links": {
"posts.comments": "http://example.com/posts/{posts.id}/comments"
},
"posts": [{
"id": "1",
"title": "Rails is Omakase"
}, {
"id": "2",
"title": "The Parley Letter"
}]
}
Rabl能做到这一点吗?试试这样的方法:
{
"links": {
"posts.comments": "http://example.com/posts/{posts.id}/comments"
},
"posts": [{
"id": "1",
"title": "Rails is Omakase"
}, {
"id": "2",
"title": "The Parley Letter"
}]
}
对象错误
节点(:链接)do
{“posts.comments”=>“http://example.com/posts/{posts.id}/comments“}
结束
孩子(@posts)怎么办
属性:id,:title
结束