Accessing validates_... , :message => 'something'

Hi,

i have a validates_something_of_something method in my User model…i
added a :message => “you need to abcd” to the validation method, but
when i try to access it through the <%= error_messages_for “user” %> it
doesn’t give me any output…

i was wondering whether there was a way to access all of the (:message
=> string) methods that are collected from the validation methods in the
model; even building my own error helper or something (from the
validates_abc, :message => string) to shape it to my own liking…where
do i start from ?

?

many thanks…

I do believe your supposed to pass in the i-var, not a string or symbol:

<%= error_messages_for @user %>

You can also loop through the error messages yourself this way:

@user.errors.each_full_messages do |message| stuff; end

Jason

On 9/12/06, Jason R. [email protected] wrote:

I do believe your supposed to pass in the i-var, not a string or symbol:

String. At least the source handles strings; maybe symbols too, I’m a
bit fuzzy on that. Note line 105.

File

vendor/rails/actionpack/lib/action_view/helpers/active_record_helper.rb,
line 103
103: def error_messages_for(object_name, options = {})
104: options = options.symbolize_keys
105: object = instance_variable_get(“@#{object_name}”)


Imagination is more important than knowledge. – Albert Einstein