ruby - Errors.add with object instance as message -
i have form custom calendar validation routine. want able display lot of dynamic information error user.
in sense errors.add(:base, "this wrong because ...")
not cut it. got idea pass in instance of object performs actual validation errors array. leave view cherrypick bits of information wanted calling methods on instance.
in model validation routine have:
errors.add(:date_range, [calendar] )
in view, this:
<p><%= @event.errors[:date_range].first.first.parse_events.to_sentence %></p>
i had add array literal, otherwise empty?
method rails calls fail.
even though works, smells bad! thought using render_to_string
instead, cannot called (or should not called) model.
any suggestions on how improve this?
Comments
Post a Comment