I have a custom form builder. In it I have a method for retrieving
validation error messages.
Currently it gets used like this:
<% form_for :my_obj…
<%= form.draw_invalid_msg(my_obj.errors[:userHosts]) %>
I would like to reduce that to this:
<%= form.draw_invalid_msg(:userHosts) %>
My method code would that start with something like this:
invalid_messages = @object_name.errors[field_name]
Well, that doesn’t work, of course, because @object_name is just a
symbol, not the actual AR object data. So, yes, I could explicitly
pass in the obj to start with, but that’s exactly what I am trying to
So, what introspective tricky can be used to yield access to the
actual object within :my_obj via the @object_name ivar value?