Actually, you need to change another line as well... from:
"#{pluralize(object.errors.count, "error")} prohibited this
#{object_name.to_s.gsub("_", " ")} from being saved"
to:
"#{pluralize(object.errors.count, "error")} prohibited this
#{object.class.to_s.downcase} from being saved"
I guess you do lose a bit of functionality here, because if you had
done...
@guy = Person.find_by_name(''Jim'')
And then...
error_messages_for ''guy''
It would say:
1 error prohibited this guy from being saved
Whereas now you would only get:
1 error prohibited this person from being saved
It''s probably not a big deal, but just so you know..., I personally
like
it the new way, but that''s just me. Also, if you had a BadPerson class
it will now say ''1 error prohibited this badperson from being
saved'', so
you might want to reformat it a bit and put a space before each capital
letter.
Cheers, Jonathan
-----Original Message-----
From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
[mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On
Behalf Of Jonathan Viney
Sent: Friday, 9 December 2005 5:29 p.m.
To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
Subject: RE: [Rails] 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.
-----Original Message-----
From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
[mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On
Behalf Of Parker
Thompson
Sent: Friday, 9 December 2005 3:42 p.m.
To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
Subject: [Rails] possible rails bug? form errors and scoping
I''m trying to render a _form partial in a separate controller and
running
into a nil object exception on the error_messages_for call. What is
interesting is that when I remove that line the form registers just
fine,
indicating the object is not nil.
I''m wondering if I''m missing something, or if this is an error
(I''m not
sure how error_message_for works internally) with the rails framework?
Thanks much,
pt.
------
Parker Thompson
Professional
(w) http://placesite.com
(c) 510.541.0125
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails