Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable ActiveModel::Serializers for a specific controller?

We're using active_model_serializers - 0.8.1 in a Rails application.

The app has some API specific controllers inheriting from ActionController::Metal in a way similar to rails-api's ActionController::API.

Well we want to use ActiveModel::Serializers only for the API controllers mentioned above.
Is that possible, how?

Note:
As mentioned in the documentation use of a serializer can explicitly be avoided by replacing

render :json

with:

render :json => @your_object.to_json

We are seeking a more elegant solution than the one above.
Thanks.

like image 357
Dimitris Zorbas Avatar asked Nov 20 '13 16:11

Dimitris Zorbas


2 Answers

For people who encounter this question in the future, adding adapter: nil to the render: json... will work (instead of serializer: nil)

like image 161
Mạnh Vũ Avatar answered Oct 25 '22 17:10

Mạnh Vũ


You can also do:

respond_with @your_object, serializer: nil
like image 41
dbj Avatar answered Oct 25 '22 16:10

dbj