Adding an ActiveRecord helper

Hi,

for ActiveRecord, there is the helper “error_messages_for”. I would like
to extend this, in order to make it possible to spit out validation
errors for more than one model object. Where would I have to place my
code in order to make the new helper work appropriately? I defined it as
a helper for my view, which lead to unwanted behaviour.

TIA,
Robert

well error_messages_for is an ActionView Helper, not an ActiveRecord
Helper.

so defining your own “version” of it as a helper for your view would be
the right way to go.

what “unwanted behaviour” did occur ? Maybe show some code how your
helper looks right now.

Thorsten L wrote:

well error_messages_for is an ActionView Helper, not an ActiveRecord
Helper.

so defining your own “version” of it as a helper for your view would be
the right way to go.

what “unwanted behaviour” did occur ? Maybe show some code how your
helper looks right now.

I did something like objects.collect{|o| instance_variable_get("@#{o}")}

which always gave me nil as the result for each instance_variable_get -
which kind of makes sense because it was a view helper and not a class
helper.

I’ve got it working though, thanks :slight_smile:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs