Possible Duplicate:
Model Using Modules in Rails Application
I have a User model that is getting really fat and I want to break it up into submodules that correspond to the different interactions such as a user's interaction with friendships, interaction with events, interaction with weapons, etc. etc. What's the best way to go about it?
The goal is to do something like:
u = User.find(1)
friend = User.find(2)
u.friends_with? friend
This is my attempt thus far: create app/models/user_helper/friendship.rb which has the code as
module UserHelper
module Friendship
def friends_with? friend
::Friendship.are_friends(self, friend) #this should point to the top-level Friendship class
end
....code code code code....
end
end
then in the User model,
include ::UserHelper::Friendship
Doesn't work though and I get undefined method when I do "User.first.friends_with?"
What I know WILL work is if I have a random file in the models directory like "UserFriendshipHelper.rb" defining
module UserFriendshipHelper
and include that, but I kinda would like to do it in a more encapsulated, organized way. Any tips or resources much appreciated.
Thanks!