-
Notifications
You must be signed in to change notification settings - Fork 899
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
user_for_paper_trail should return an id instead of a user #316
Comments
As it says in the API section of the README, you should feel free to override these methods as you see fit. You can define it on your Here is what I put in the def current_user_id
@current_user_id ||= current_user.try(:id)
end
alias_method :user_for_paper_trail, :current_user_id |
@batter yeah, that's what I've done. But I am just curious about:
Thanks. |
In my case, we were using UUID's, so it made more sense to keep it as a I'm not sure what you mean by your 2nd question. I believe the reason why it wouldn't be an issue when you're You could be right, it might make sense to have the default value for |
I think my thought process at the time went like this:
However I checked the application from which I extracted paper_trail in the first place. The application controller has this method: def user_for_paper_trail
current_user.try :id
end So it looks like I made a mistake during the extraction and had the Oops. In the end it possibly worked out ok that way because not all apps would want Anyway, I think it was a bit of a blunder. Sorry about that ;) |
That is very interesting because I didn't override So by the sound of it |
I don't think it's extremely important what the return value defaults to for |
I did run into an issue with this when attempting to use prepared statements with the JDBC mysql driver in JRuby. The driver simply calls def user_for_paper_trail
current_user.andand.id
end So I would argue that it is actually important for |
Yes, what's the point returning object at all if the gem is expecting an |
…n id instead of an object. close #316
I believe the documentation should be updated to cover this. It currently says |
You're right, looks like the docs need to be updated. I will try to give them an update this afternoon, thanks for pointing that out. |
👍 :-) |
@sjobe - I just pushed b106aef, is that a better / more accurate summary of the behavior? Here is the the default method definition for |
@batter in this commit why are you returning When do you expect a That looks even more inconsistent and confusing :( Seriously, just return This will raise explicit and obvious error if there's no Why use It's much easier to look at the method:
than the one in the commit. And there's no benefit for the complexity of a method. Also I can understand the check for the existance of But think about this. 99% of use cases we want the versions with Sometimes there's just too much magic for no benefit :) Please have a thought about it and consider this. Just my $0.02. |
@dnagir - simply put, not all Also, that is not a recent commit, that has been the implementation since v3.0.1. See #346 for historical context as to why it works the way it does. |
@batter yes, the update definitely is a better description of what's happening. thanks! |
Ben, curious where did you see the user object that doesn't respond to id? On Fri, 10 Apr 2015 7:39 am Serign Jobe [email protected] wrote:
|
The
user_for_paper_trail
on the controller returns the thecurrent_user
when available.I'm not sure why the user (rather than an
id
) should be returned from there because thewhodunnit
column is a string.This became a problem when I changed the type of
whodunnit
from a string to an integer (so that I can join on thewhodunnit
in SQL queries). As a result, thewhodunnit
column is no longer being saved.The workaround was to override
user_for_paper_trail
:Either way,
user_for_paper_trail
needs to correspond to whatever type ofwhodunnit
is.Does that make sense?
The text was updated successfully, but these errors were encountered: