Note that there are some explanatory texts on larger screens.

plurals
  1. POSuppress "base" in error text for custom validation of Rails nested attributes
    primarykey
    data
    text
    <p>I have the following models:</p> <pre><code>class Evaluation &lt; ActiveRecord::Base attr_accessible :product_id, :description, :evaluation_institutions_attributes has_many :evaluation_institutions, :dependent =&gt; :destroy accepts_nested_attributes_for :evaluation_institutions, :reject_if =&gt; lambda { |a| a[:token].blank? }, :allow_destroy =&gt; true validate :requires_at_least_one_institution private def requires_at_least_one_institution if evaluation_institution_ids.nil? || evaluation_institution_ids.length == 0 errors.add_to_base("Please select at least one institution") end end end class EvaluationInstitution &lt; ActiveRecord::Base attr_accessible :evaluation_institution_departments_attributes, :institution_id belongs_to :evaluation has_many :evaluation_institution_departments, :dependent =&gt; :destroy accepts_nested_attributes_for :evaluation_institution_departments, :reject_if =&gt; lambda { |a| a[:department_id].blank? }, :allow_destroy =&gt; true validate :requires_at_least_one_department private def requires_at_least_one_department if evaluation_institution_departments.nil? || evaluation_institution_departments.length == 0 errors.add_to_base("Please select at least one department") end end end class EvaluationInstitutionDepartment &lt; ActiveRecord::Base belongs_to :evaluation_institution belongs_to :department end </code></pre> <p>I have a form for Evaluation that includes nested attributes for EvaluationInstitution and EvaluationInstitutionDepartment, so my form is nested to 3 levels. The 3rd level is giving me a problem.</p> <p>The errors are triggered as expected, but when the error triggers for requires_at_least_one_department, the text reads </p> <blockquote> <p>Evaluation institutions base Please select at least one department</p> </blockquote> <p>The message should read "Please select at least one department".</p> <p>How do I remove "Evaluation institutions base"?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload