Last active
September 8, 2020 16:46
-
-
Save thijsnado/a81a42caaeffaf5b951a to your computer and use it in GitHub Desktop.
Example of ActiveModel::Serializer selectively
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Gemfile | |
gem 'active_model_serializers', require: false | |
# config/initializers/active_model_serializers.rb | |
require "active_model" | |
require "active_model/serializer/version" | |
require "active_model/serializer" | |
require 'action_controller/serialization' | |
# in controller where you want to use active model serializer | |
class SomeController < ApplicationController | |
include ::ActionController::Serialization | |
end |
@fermion, sorry for late response. I think when I wrote this way back in 2014, we wanted to use active model serializers but they monkey patch rails in ways that made our test suite failed. This was a way of only using those serializers on controllers selectively. Not sure if it still works.
No worries. Can't believe that you actually found this 😆
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is this to avoid explicitly declaring the serializer Class to use for a given response?