我Product
類有price
字段,它具有在Products
表在數據庫中,和new_shop
輔助字段適當的柱(其被定義爲attr_accessor
,並在數據庫中不具有Products
表中的適當列)。Rails 3:爲什麼錯誤的字段在驗證失敗時沒有用「field_with_errors」div封裝?
當price
驗證失敗,則輸入字段是包裹着field_with_errors
格,但是當上new_shop
驗證失敗,它不與field_with_errors
DIV纏繞。爲什麼?
下面是這些輸入字段生成的HTML:
<input type="text" name="product[price]" id="product_price">
<input type="text" value="" name="product[new_shop]" id="product_new_shop">
一些更多的信息:
class Product < ActiveRecord::Base
attr_accessor :new_shop
accepts_nested_attributes_for :shop
validates_presence_of :price
...
end
class Shop < ActiveRecord::Base
validates_presence_of :name
...
end
當表單提交後,new_shop
值傳遞給產品的shop_attributes[:name]
。
請包括驗證碼 – kikito 2010-12-21 01:29:20
我更新了問題。 – 2010-12-21 01:36:12