RE: possible rails bug? form errors and scoping

I think you’ve run into the same thing I did. error_messages_for takes a
string as its first parameter and then looks for an instance variable by
that name.

def error_messages_for(object_name, options = {})
options = options.symbolize_keys
object = instance_variable_get("@#{object_name}")
unless object.errors.empty?

end
end

So if you do error_messages_for(‘person’) it will generate the errors
for @person. I personally think this should be changed, I can’t see why
it takes a string in anyway… but I guess there could be a reason.

A simple fix is to just pass in the object itself, so it becomes:

def error_messages_for(object, options = {})
options = options.symbolize_keys
unless object.errors.empty?

end
end

(Put the above in application_helper.rb). So you now call it like
error_messages_for person, not error_messages_for ‘person’. That should
work fine.

Cheers, Jonathan.