In my plugin I'm inheriting few models from the engine and adding Mobility settings.
# my enginge
module MyEngine
class Foo < ApplicationRecord
def self.say_hi
return "hi"
end
end
end
# my plugin
require 'my-engine'
module MyEngine
class Foo
include Mobility
translates :name, type: :string
end
end
Now if I look for the model in Rails console:
MyEngine::Foo.say_hi
ArgumentError: KeyValue backend can only be used by ActiveRecord or Sequel models
If I comment out Mobility settings everything works:
MyEngine::Foo.say_hi
=> "hi"
How to extend in my app an AR model MyEngine::Foo
so Mobility doesn't complain?
This answer does help with extending an engine model from a plugin, but doesn't help with mobility.
To use modify
MyEngine::Foo
to use mobilty you need to create an initializerconfig/initializers/mobility_models_extension.rb
(make sure the file name is alphabetically aftermobility.rb
file).See
send
documentation and initializers documentation