Skip to content

Instantly share code, notes, and snippets.

@thijsnado
Last active September 8, 2020 16:46
Show Gist options
  • Save thijsnado/a81a42caaeffaf5b951a to your computer and use it in GitHub Desktop.
Save thijsnado/a81a42caaeffaf5b951a to your computer and use it in GitHub Desktop.
Example of ActiveModel::Serializer selectively
# 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
Copy link

fermion commented Oct 6, 2014

Is this to avoid explicitly declaring the serializer Class to use for a given response?

@thijsnado
Copy link
Author

@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.

@fermion
Copy link

fermion commented Sep 8, 2020

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