Problem when inheriting subclass

20 views
Skip to first unread message

Daniel Faiole

unread,
Aug 16, 2017, 1:21:58 PM8/16/17
to Ruby on Rails: Talk
Hi,
I can't seem to find anything on the web regarding this error I found. I don't know if it's something i did wrong or just some kind of bug.

I have 2 engines, named "Pes" and "Iss". "Pes" is the most atomic engine in our project and all other engines will add it as a dependency, it has these models:

Pes::Person
Pes::Person::Phone

The "Iss" engine depends on "Pes" and has these models that inherits from "Pes"

Iss::Person < Pes::Person
Iss::Person::Phone < Pes::Person::Phone

My problem is that, when I call Iss::Person.new, rails gives me an Iss::Person object... Great! But when I call Iss::Person::Phone, rails is giving me a Pes::Person::Phone object... I tried everything, and even when i remove the inheritance from the Iss::Person::Phone model, it still gives me the Pes::Person::Phone object.

Here's some sample code:

module Pes
  class Person < ApplicationRecord
     ...
  end
end

module Pes
  class Person::Phone < ApplicationRecord
     ...
  end
end

module Iss
  class Person < Pes::Person
     ...
  end
end
 
module Iss
  class Person::Phone < Pes::Person::Phone
     ...
  end
end

I'm using rails 4.2.9, but i tried to update to 5.0.2 and it still giving me this bug, I still haven't tried using rails >= 5.1

Also, sorry if my english doesn't make much sense, i'm from Brasil

Jacopo Beschi

unread,
Aug 17, 2017, 8:27:06 AM8/17/17
to Ruby on Rails: Talk
I think you could solve your problem by explicitly writing all modules and moving the file in the appropriate foder, this should solve your autoloading issues. 
For example for Pes::Person::Phone you should do this:

module Pes
   module Person
      class Phone
      end
  end
end

and you need to put this file into pes/person/phone.rb
Reply all
Reply to author
Forward
0 new messages