2012-02-27 28 views
0

問題我有一個窗體,顯示2個模型的輸入,我正在使用accep_nested_attributes_for。來自模型的Rails錯誤消息,有沒有一種方法來訂購它們?與accepted_nested_attributes_for

在具有accepts_nested_attributes_for我的主力機型,它看起來像:

class Account < 
    accepts_nested_attributes_for :primary_user ... 

現在在我的形式,我對@account一個的form_for,然後有fields_for的primary_user模型。

如果我點擊提交,出於某種原因,首先顯示primary_user的所有錯誤。我寧願讓錯誤以與網頁上的輸入字段相同的順序顯示。

  1. 這是可能的重新排序他們根據他們是如何在我的form_for命令?

  2. 此外,錯誤消息有'主用戶名不能爲黑',是否可以將其更改爲'用戶名不能爲空'?我並不需要將最終用戶與「主要」這個詞混淆起來,因爲它對他們來說確實沒有意義,它更像是一種內在的東西。

回答

-1

不知道的重新排序,但你可以按照如下更改消息的模型驗證:

validates :username, presence: { message: "Username cannot be blank" } 
相關問題