I am working on a rails app where I have 2 different types of Users (MasterClientUser and AccountManager). I am using single table inheritance to differentiate the users. I have a update_last_seen_at private method that will need to be called on both the AccountManager and the MasterClientUser. I am attempting to put it in the User model but I get the following error:
private method `update_last_seen_at' called for #<MasterClientUser:0x007fc650d2cad0>
The update_last_seen_at method is called from the HomeController:
class HomeController < ApplicationController
before_action :authenticate_user!, :save_users_access_time, only: [:index]
def index
@user = current_user
end
def save_users_access_time
current_user.update_last_seen_at
end
end
Models
class User < ActiveRecord::Base
end
class MasterClientUser < User
private
def update_last_seen_at
self.update_attributes(last_seen_at: Time.now)
end
end
class AccountManager < User
end
I have also tried putting the method in a module and including the module in each of the different User types, but I get the same error.
Is there any way that I can share the method for both User types and keep it private without having to put them in each model explicitly?/ is there a better strategy go about solving this issue.