So I have a project with authentication of users, and history tracking of some models. For the history I use the paper_trail gem, I have a problem of filtering the history to show to the user, I have configured it to track the current_user id into the Whodunnit field. My user has role_id which specifies the role from the Roles table Also i have another table with some items that have id and user_id fields. And now my problem is how to take specific rows from Versions table according to the role of the user, like for ex: if user role is 'SomeRole' it has to return only those actions done by the users that have the same role 'SomeRole'. I know that i can take out all the actions by
@versions = PaperTrail::Version.order('created_at')
but have no idea on how to filter to select only those that are satisfying for my uses. Is there an easy way to do it or should i hardcode it like selecting one by one, than check all user_id of their roles and so on so forth? Hope you understood my messy way of explaining
In similar situation I used this solution:
1) Added user_id field to versions
(whodunnit is a text field and I didn't want to use it as association key)
2) Defined association in Version model:
and in User model:
3) Set info_for_paper_trail in ApplicationController (or where you need it)
So I'm able to access versions like:
So in your case it would be: