error_messages_for

Is there any particular reason why error_messages_for doesn't let you pass the object you want error messages for (in case it's not in the instance variable)?
Similarly if you do

form_for :person, some_random_object do |f|
   f.error_messages
end

Then it doesn't work because that just ends up calling error_message_for('person') although there is @person.

This looks very easily fixable but I was wondering if there was a deeper reason to it or it was just oversight (in which case I'll write up a patch)

Fred

Is there any particular reason why error_messages_for doesn't let you
pass the object you want error messages for (in case it's not in the
instance variable)?
Similarly if you do

form_for :person, some_random_object do |f|
   f.error_messages
end

Then it doesn't work because that just ends up calling
error_message_for('person') although there is @person.

This looks very easily fixable but I was wondering if there was a
deeper reason to it or it was just oversight (in which case I'll
write up a patch)

I'm not aware of any philosophical reason for that behaviour, so
please send in a patch.

I've created a patch at http://dev.rubyonrails.org/ticket/9699

Fred

Hi,

There's already an issue open for this. I've added a patch quite a
while ago but forgot to follow up and ask for verifications.

I just updated the patch to work with latest rails.

http://dev.rubyonrails.org/ticket/9144

Cristi

Hey guys,

both those patches should really include some examples for use in the
rdoc. If someone could beef up the documentation, attach it to one of
the patches and close the other, I'd be really grateful :).

I'll credit both submitters in the changelog to avoid any conflicts.

I've added some examples to the patch at http://dev.rubyonrails.org/ticket/9699.
I've not made any changes to the form_for stuff, on the grounds that it now just works as it should (ie f.error_messages doesn't care how you created the form builder)

Fred