I am writing a rails engine gem which depends on active_model_serializers gem.
It provides `initializers/active_model_serializers.rb
# When false, serializers must be explicitly specified
ActiveModelSerializers.config.serializer_lookup_enabled = false
when i actually installed my engine, and typed rails g to show my engine generators command.
I got the following errors somehow...
➜ officepod git:(backend) ✗ rails generate
/Users/seoyoochan/.rvm/gems/ruby-2.2.4@officepod/bundler/gems/officepod-gem-58b38f9ad336/config/initializers/active_model_serializers.rb:2:in `<top (required)>': uninitialized constant ActiveModelSerializers (NameError)
from /Users/seoyoochan/.rvm/gems/ruby-2.2.4@officepod/gems/railties-4.2.5/lib/rails/engine.rb:652:in `block in load_config_initializer'
My guess is that it is caused by the old version, which is active_model_serializers (0.9.4)
upgrading to v0.10.0.rc4 didn't work out
I fixed it by adding require "active_model_serializers" at config/application.rb
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
require "active_model_serializers"
module Officepod
class Application < Rails::Application
@seoyoochan Thanks for your report and resolution! :dancer:
@bf4 actually there is other solution.
you can explicitly write gem "active_model_serializers", require: true at Gemfile instead of requiring it at config/application.rb
If someone will ever come here with the problem I have: upgrading makes a sense.
None of the fixes (require in Gemfile or in config/application.rb) didn't work for 0.9.3 but upgrading to 0.10.6 and putting require to one of the places did the trick.
Most helpful comment
@bf4 actually there is other solution.
you can explicitly write
gem "active_model_serializers", require: trueatGemfileinstead of requiring it atconfig/application.rb