Rails 3: Why is the error field not wrapped by the field_with_errors field when validation fails?

In my Productclass there is a field pricethat has a corresponding column in the table Productsin the database and new_shopan auxiliary field (which is defined as attr_accessorit does not have the corresponding column in the table Productsin the database).

When the check for pricefails, the input field completes with the field_with_errorsdiv, but when the check for new_shopfails, it does not complete with the field_with_errorsdiv. 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">

Additional Information:

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 value new_shopis passed to the product shop_attributes[:name].

+3
1

: name, ? new_shop fieldWithErrors div : @product.errors, , .

#comes to do the :new_shop field
#looks to see if @product.errors.on(:new_shop) is not blank
#if it isn't blank, wraps the error div round it. 
+3

Source: https://habr.com/ru/post/1781356/


All Articles