error_messages_for doesn't work

I'm having a problem, 'cause I wrote the following line in my model "Hi":

[code] validates_numericality_of :phone, :only_integer => true, :allow_blank => false, :message => "must be a number" [/code]

And in my "new" view, I put:

[code] <%= error_messages_for :oi,                     :header_message => "Erro ao cadastrar usuário." ,                     :message => "Cheque o(s) seguinte(s) campo(s):"%> [/code]

Rails notice the error, because I can't save a Hi object with phone not being a number; but it doesn't show me the errors that was find.

What it should be?

Thanks for any help.

I'm having a problem, 'cause I wrote the following line in my model "Hi":

[code] validates_numericality_of :phone, :only_integer => true, :allow_blank => false, :message => "must be a number" [/code]

And in my "new" view, I put:

[code] <%= error_messages_for :oi,

I think that should be hi not oi, and I think you have to put the model name in quotes also, so error_messages_for 'hi', .....

Colin

Yeah, I'm sorry.

Actually, I wrote it wrong here, in the forum.

It's:

[code] <%= error_messages_for :hi,                     :header_message => "Error." ,                     :message => "Check the following camps:"%> [/code]

What's in your controller ?

Fred

this tag "[code]" and "[/code]" is just to let everyone know where begins and where ends my code. It's not in my controller...

Yeah, I'm sorry.

Actually, I wrote it wrong here, in the forum.

It's:

[code] <%= error_messages_for :hi, :header_message => "Error." , :message => "Check the following camps:"%>

The docs at http://api.rubyonrails.org/classes/ActionView/Helpers/ActiveRecordHelper.html#M002221 show the name in quotes, as I suggested in my previous post. So error_messages_for 'hi', ... have you tried that?

Colin

I try to put in quotes, but it also doesn't works...

Bla ... wrote:

I try to put in quotes, but it also doesn't works...

Can you paste the content that it renders? Also, does anything scroll by in your server window when you try this?

Additionally, wanted to mention that error_messages_for was removed from Rails 3, though available as a plugin. So maybe consider just going with a custom solution now. Here is an snippet that I've used, though note it is in HAML, not ERB.

# views/shared/_error_messages.html.haml

- if target.errors.any?   #errorExplanation     %h2= "#{pluralize(target.errors.count, 'error')} prohibited this record from being saved:"     %ul       - target.errors.full_messages.each do |message|         %li= message

Then used with

# views/thingy/_form.html.haml

#errors= render 'shared/error_messages', :target => @company

You get a bit more control over what is going on here and are protected against the imminent removal of the helper.