Skip to content

Commit

Permalink
Fix the case where username is nil, not whodunnit
Browse files Browse the repository at this point in the history
I encounter the problem where paper_trails's whodunnit isn't displayed.
It turned out that `username` method returns nil.
`try` method returns nil when there's no method, so when user doesn't have `email` method,
`@user_class.find(@version.whodunnit).try(:email)` returns nil.
Then, try this out:
`nil rescue nil || :foo`
This returns nil, surprisingly.
This means if user doesn't have email method, username is always nil.
So my fix is like below:
`(nil rescue nil) || :foo`
This returns `:foo` as expected.
  • Loading branch information
okuramasafumi committed Nov 1, 2019
1 parent a6296d0 commit 5f35e90
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rails_admin/extensions/paper_trail/auditing_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def table
end

def username
@user_class.find(@version.whodunnit).try(:email) rescue nil || @version.whodunnit
(@user_class.find(@version.whodunnit).try(:email) rescue nil) || @version.whodunnit
end

def item
Expand Down

0 comments on commit 5f35e90

Please sign in to comment.