My Product
class has price
field, which has an appropriate column in Products
table in the database, and new_shop
helper field (which is defined as attr_accessor
, and does not has an appropriate column in Products
table in the database).
When validation on price
fails, the input field is wrapped with field_with_errors
div, but when the validation on new_shop
fails, it is not wrapped with field_with_errors
div. Why ?
Here is the generated HTML for these input fields:
<input type="text" name="product[price]" id="product_price">
<input type="text" value="" name="product[new_shop]" id="product_new_shop">
Some more info:
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
When the form is submitted, the new_shop
value is passed to product's shop_attributes[:name]
.