目前我想顯示我的錯誤,我同時添加到用戶對象控制器內我的模型內部驗證顯示。我如何保存錯誤在模型內部的容器,並在控制器
好像如果我的控制器中有錯誤,立即顯示它然後返回並且不顯示模型內的錯誤,我知道如果我的錯誤完成計數並顯示所有錯誤,一。
我甚至寫了應檢查模型內部的驗證,並將它們保存到我的對象則顯示錯誤的方法可以顯示所有的錯誤,包括驗證方法是在模型中發現了一個人的。
我控制器的方法是這樣的
def info
if @user.firstname != "" && @user.lastname != "" && @user.id_number != "" && @user.email != ""
@user.errors.add_to_base("Password can't be blank")
end
end
def validations()
@errors = User.check_validations
end
def display(template_to_render)
if @user.errors.count >= 1
render :action => template_to_render
end
end
然後我在模型方法如下
def self.check_validations validates_presence_of :firstname, :lastname, :date_of_birth, :if => Proc.new { |o| o.force_update? || o.profile_confirmed? } end
的話,我想驗證方法的所有錯誤添加到@ user.errors.to_base錯誤 ,並顯示它們。
,所以我想知道是否有任何方法也許我可以用它來檢查模型內部的方法,而且所有這些錯誤添加到@user對象纔可以在該視圖中顯示。