i have big project
model, , use many tabs show different parts of form.
the idea : each tab regroups specific subset of fields model, , if there error, highlight title of tab in red.
it simple nested associations, because have check object.errors[:association].any?
but other fields, tedious do
object.errors[:name] or object.errors[:start_date] or object.error[:end_date]...
is there way group errors ? following should return true if there errors in either :name, :start_date
...
object.errors[:basic_params].any?
in html looks this
<ul class="nav nav-tabs" role="tablist"> <li><a href="#tab-summary" data-toggle="tab">résumé</a></li> <li><a href="#tab-echanges" data-toggle="tab" <%= 'class="text-danger"'.html_safe if @etude.errors[:echanges].any? %>>echanges</a> </li> <li><a href="#tab-params" data-toggle="tab" <%= 'class="text-danger"'.html_safe if @etude.errors[:basic_params].any? %>>paramètres</a> </li> <li><a href="#tab-phases" data-toggle="tab" <%= 'class="text-danger"'.html_safe if @etude.errors[:phases].any? %>> phases</a> </li> <li><a href="#tab-candidatures" data-toggle="tab" <%= 'class="text-danger"'.html_safe if @etude.errors[:competences].any? %>> candidatures</a> </li>
i know in mean time can this, i'd have error grouping system.
[:name, :start_date, :end_date].each |field| return true if object.errors.include?(field) end
i can't match desired :[]
lookup syntax precisely, if want do, why not use structure following?
example_params = [:name, :start_date, :end_date] errors.any? { |e| example_params.include? e }