问题
I want to get current user's name. As documentation describes, I should user User.name method. Tried to use it as in the example - didn't work. Tried this:
val = User.current.name
And this:
user = User.find(User.current.id)
val = user.name
What am I doing wrong?
回答1:
Unless you do something strange with your Redmine instance, you should always have a User.current
. So you should also be able to use User.current.name
.
As this did not work, as you said, could you please elaborate a bit on what exactly didn't work?
回答2:
You need a session or a cookie with a current user assigned (see the application controller) so you cant just console in and ask for the current user.
来源:https://stackoverflow.com/questions/3653281/user-name-in-redmine