我需要知道模型中当前用户的 ID:
def after_save
desc, points=nil, nil
if answer_index == daily_question.correct_answer_index
desc = I18n.t('daily_question.point_log.description.correct')
points=daily_question.points
else
desc = I18n.t('daily_question.point_log.description.incorrect')
end
current_user.give_points(:description => desc,
:points => points
)
end
但我想这不是怎么做的?
问候,
雅各布
最佳答案
假设用户已登录,您可以使用UserSession.find.user
您可能需要添加检查以确保 UserSession.find
在调用之前返回一些东西 .user
关于ruby-on-rails - 模型中的 Authlogic 的 current_user 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2476624/