2012-09-07 48 views
0

User.first.current_sign_in_at顯然是我想要使用的,但是如何將其添加到鉤子中?Rails - 當用戶登錄時嘗試使用用戶掛接找出方法時不存在錯誤 - devise

before_save :login_hook, :if => current_sign_in_at_changed? 

但我得到的方法不存在。

這似乎工作:

Execute JS code on user sign up/sign in with Rails + Devise

我已經設計:可跟蹤模型和t.trackable在我的遷移。該數據庫值也更新

+0

有一個devise的幫手'user_signed_in?' – Eru

+0

你在哪裏添加這個鉤子? –

回答

1

現在,忘了鉤,就嘗試使用

if (Time.new - current_user.last_sign_in_at) < 600 # seconds, so 10 minutes 
    do stuff 
else 
    # do other stuff, probably a redirect 
    # possibly sign_out_and_redirect(resource_name) 
end 

你可能想這在你的application_controller,以便適用於所有。

+1

我需要知道用戶是否登錄,如果他登錄不了 – Ben

+0

用不同的方法更新。 –

+0

非常好,謝謝 – Ben

相關問題