How can I have a certain set of controllers use a different adapter?
I think I can do something like this in a before_filter
:
ActiveModel::Serializer.config.adapter = :json
Then on another set of controller's before_filter
:
ActiveModel::Serializer.config.adapter = :json_api
The code won't be threadsafe though..
Based on the code, you can specify the adapter in your controller action like that:
render json: @users, adapter: :json_api
It is of course not that convenient, as having a before_action
in the base controller, but should be threadsafe.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.