2012-06-11 86 views
0

在用戶註冊到使用Devise的Rails 3.2.3應用程序後,會觸發after_create回調,它會嘗試創建組織記錄。after_create回調:flash消息

如果這個create驗證失敗,我怎麼能得到顯示的錯誤信息?我應該重寫設備控制器嗎?事情是,這些錯誤與組織創建有關,而不是用戶(我有一個漂亮的香草設計用戶模型設置)。

我做這樣的事情在用戶模式:

# after_create callback method 
... 
    unless new_org_user.save 
     errors.add("Warning", "Organisation is invalid") 
    end 
... 

回答

0

既然你是射擊在after_create回調記錄已成功創建所以沒有閃光燈消息將apear事件。

你爲什麼不嘗試把它移動到關係協會,而不是和孩子需要驗證像

class User < ActiveRecord::Base 
    has_one :organization 
    accepts_nested_attributes_for :organization 
end 

class Organization < ActiveRecord::Base 
    belongs_to :user 
end 

這樣,如果組織不合法,將無法驗證