【发布时间】:2015-09-24 18:05:05
【问题描述】:
我知道这个版本还没有正式发布,但是我今天检查了 rc3,我注意到我不能再在我的序列化程序中使用 Rails url 帮助程序。在 0.8.x 版本中,我可以执行以下操作:
class BrandSerializer < BaseSerializer
attributes :id, :name, :slug, :state
attributes :_links
def _links
{
self: api_v1_company_brand_path(object.company_id, object.id),
company: api_v1_company_path(object.company_id),
products: api_v1_company_brand_products_path(object.company_id, object.id)
}
end
end
但这在新版本中是不行的。解决此问题的最佳方法是什么,以便我可以将链接保留在序列化程序中?
编辑: 现在我正在做以下事情,但很想听听是否有更惯用的方式。
class BaseSerializer < ActiveModel::Serializer
include Rails.application.routes.url_helpers
【问题讨论】:
-
我认为你回答得最好
标签: ruby-on-rails active-model-serializers