Url Helpers in ActiveModelSerializer 0.10.0?

折月煮酒 提交于 2019-12-04 23:52:38

If you add this to your ApplicationController or even probably to the controller generating the response:

serialization_scope :view_context

You can then use the view_context in the serialiser to access the URL helpers (or any view methods really).

Example: view_context.api_v1_company_brand_path(object.company_id, object.id)

I thought this was probably cleaner than including all those URL helpers etc... into the serialiser class.

including the library which had been excluded (as you had done) would most definitely be the shortest route (outside of revising the gem itself, in terms of idiomacy)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!