0

I have an app with a user model in app/models/user.rb.

Now I wrote an engine witch needs additional methods in the user class.

class User < ActiveRecord::Base
  # some code
end 

When I add a user model to vendor/plugins/foo/app/models/user.rb with additional methods, the methods are undefined and rails cant find them.

class User < ActiveRecord::Base
  # some additional code
end

When I add a foo_user model which inherit from User, it works, but this is not what I would to have :(

class FooUser < User
  # some additional code
end

How may I extend the User class from the origin App in the engine?

tshepang
  • 12,111
  • 21
  • 91
  • 136
Piioo
  • 759
  • 10
  • 24

1 Answers1

0

When defining the User model you set the inheritance scheme, in the first scenario both instance and class methods are inherited from ActiveRecord::Base.

Since you want to use the methods defined in your custom User model you will need to extend this functionality in your seperate class: FooUser in this case.

I do not know why you're convinced such method of implementing is not wanted, since it's the way Rails is setup.

Another way to implement an array of methods is monkey patching, here is another SO question on the subject: Monkey Patching in Rails 3

Community
  • 1
  • 1
dennis
  • 2,000
  • 18
  • 26