Ruby on rails 如何让Grape以正确的格式为ember.js生成JSON?

Ruby on rails 如何让Grape以正确的格式为ember.js生成JSON?,ruby-on-rails,ember.js,ember-data,grape,Ruby On Rails,Ember.js,Ember Data,Grape,与之类似,我想知道如何定制Grape(构建在Rails之上)来发送hasMany与请求对象的所有相关ID,因为Ember期望这种格式: { "customer": { "projects": [1, 2, 3] } } 因为Grape有自己的连载程序,所以我不能这样做 class PostSerializer < ActiveModel::Serializer embed :ids attributes :id, :title, :body has_many :commen

与之类似,我想知道如何定制Grape(构建在Rails之上)来发送hasMany与请求对象的所有相关ID,因为Ember期望这种格式:

{ "customer": { "projects": [1, 2, 3] } }
因为Grape有自己的连载程序,所以我不能这样做

class PostSerializer < ActiveModel::Serializer
  embed :ids

  attributes :id, :title, :body
  has_many :comments
end
class PostSerializer

有没有像
embed:ids
这样的简单解决方案,或者我必须手动添加ID吗?

使用grape实体,它将类似于:

class CustomerEntity < Grape::Entity
  expose (:projects) { |entity| entity.projects.pluck(:id) }
end
class CustomerEntity
使用grape实体,它将类似于:

class CustomerEntity < Grape::Entity
  expose (:projects) { |entity| entity.projects.pluck(:id) }
end
class CustomerEntity
谢谢,我试试看。否则,我可以使用。或者出于某些原因我应该使用Grape实体吗?对Grape使用序列化程序几乎从来都不是一个好主意。在0.3版之前,所有的元素都被嵌入到葡萄中,我会试试看。否则,我可以使用。或者出于某些原因我应该使用Grape实体吗?对Grape使用序列化程序几乎从来都不是一个好主意。在0.3版之前,实体被嵌入到grape中