用户每天 he/she 第一次登录应该获得积分
The first time a user logs in per day he/she should receive points for it
我有一个方法可以在用户每天登录一次时给用户打分。如何确定用户每天进入系统一次?我正在使用设计身份验证系统。
::Gamification::RewardUserForLoggingJob.perform_later(user)
如果使用 devise,您应该首先将 :trackable
符号包含到您的用户模型中。 this question 的答案应该告诉您您的用户模型和 table 应该是什么样子。
:trackable
将添加以下信息:
sign_in_count # Increased every time a sign in is made (by form, openid, oauth)
current_sign_in_at # A timestamp updated when the user signs in
last_sign_in_at # Holds the timestamp of the previous sign in
current_sign_in_ip # The remote ip updated when the user sign in
last_sign_in_ip # Holds the remote ip of the previous sign in
然后,您需要在用户模型中使用一个方法来检查用户上次登录是否不是今天:
# models/user.rb
def daily_reward
if self.last_sign_in_at.yday != Time.zone.now.yday
# give your points here
end
end
# controllers/sessions_controller.rb
def create
user = #YourUserQuery
if user and user.authenticate(params[:password])
user.daily_reward
# ...
end
end
我有一个方法可以在用户每天登录一次时给用户打分。如何确定用户每天进入系统一次?我正在使用设计身份验证系统。
::Gamification::RewardUserForLoggingJob.perform_later(user)
如果使用 devise,您应该首先将 :trackable
符号包含到您的用户模型中。 this question 的答案应该告诉您您的用户模型和 table 应该是什么样子。
:trackable
将添加以下信息:
sign_in_count # Increased every time a sign in is made (by form, openid, oauth)
current_sign_in_at # A timestamp updated when the user signs in
last_sign_in_at # Holds the timestamp of the previous sign in
current_sign_in_ip # The remote ip updated when the user sign in
last_sign_in_ip # Holds the remote ip of the previous sign in
然后,您需要在用户模型中使用一个方法来检查用户上次登录是否不是今天:
# models/user.rb
def daily_reward
if self.last_sign_in_at.yday != Time.zone.now.yday
# give your points here
end
end
# controllers/sessions_controller.rb
def create
user = #YourUserQuery
if user and user.authenticate(params[:password])
user.daily_reward
# ...
end
end