I am using the Audited gem in my application for tracking user log. Everything is working fine except for current user tracking.
In my case, I have 2 models: Instructor
and Student
. Instructor
will be the current_admin_user
, and I need to find the student manually.
To overcome this issue, I tried to override current_user_method
and create an audited.rb file in the initializers with below content:
Audited.current_user_method = :current_admin_user
This is working fine, but when I use any other method like current_user_or_student
...
Audited.current_user_method = :current_user_or_student
in application_controller.rb
...
def current_user_or_student
current_admin_user || InstructorStudent.find_by_id(id)
end
it is not going into this method, even current_admin_user
is also not storing in audits.
Why isn't my current_user_or_student
method being called when overriding it in application_controller.rb
?
current_admin_user
in audited.rb, it is storing user perfactly, when i use custom methodcurrent_user_or_student
it is not storing. even exit is also not working for that method – Hamancurrent_admin_user
? Are you settingAudited.current_user_method
in an initializer? Or are you attempting to change it dynamically at runtime? – KarlmarxstadtAudited.current_user_method
in audited.rb initializer. It is working fine. because current_admin_user is method of devise. i want to customize method like when current admin user change details it should show current_admin_user, but when any student change details it should show student changed detail. student is just model it is not resource of devise and instructor is resource of devise. – Haman