2010-12-21 56 views
0

我想通過設計來設置當用戶確認一個布爾標誌。基本上我想將用戶設置爲「活動」。然而,設計只是確認該帳戶並記錄他們進來修改確認與設計

我如何創建某些種類來更新我的用戶記錄確認後到「主動」欄設置爲true的回調?

任何幫助,非常感謝!

回答

1

。假定您的身份驗證模式被稱爲User,你可以這樣做:

class User < ActiveRecord::Base 
    def active? 
    super and (not self.confirmed_at.nil?) 
    end 
end 

有了這個,設計將無法登錄的用戶,但會等待用戶確認(在confirmed_at場將非NULL如果用戶已確認)

+0

確定 - 好奇,我怎麼能修改此,這樣當他們點擊電子郵件中的鏈接,還設置了「主動」標誌爲true?再次感謝您的推動。 – 2010-12-21 17:59:58

0

對於您的特定問題,您最好實施active?屬性,因爲confirmed_at爲零,正如Zabba所建議的那樣。

但是,這裏是如何去做你在問什麼,因爲它可能有助於人們試圖確認後設置其他值的用戶。

class Users::ConfirmationsController < Devise::ConfirmationsController 

    def show 
    # let Devise actually confirm the user 
    super 
    # if they're confirmed, it will also log them in 
    if current_user then 
     # and you can do whatever you want with their record 
     current_user.active = true 
    end 
    end 

end 
0

這基本上是對下面的Turadg's Answer的評論。如果您按照建議(我做了),你將有一個小問題,當用戶嘗試使用無效confirmation_token。你會得到一個「Missing template users/confirmations/new」。 Devise :: ConfirmationsController在這裏做的是發送給設計/確認/新的通知您令牌無效並允許您發送另一個令牌。

由於我已經定製了Devise視圖,我最終做了什麼來解決這個小問題,是將devise/confirmations/new.html.haml文件移動到user/confirmations/new.html下的預期位置.haml。