How to get the message from validates_presence_of

hi,

I’ve a model with validates_*_of statements, but I have no idea how to
get the :message back, anyone has a clue? Thanks.

On 9/27/06, Ianne L. [email protected] wrote:

hi,

I’ve a model with validates_*_of statements, but I have no idea how to
get the :message back, anyone has a clue? Thanks.

In your view you need to include the error_messages_for method. This
takes
a string argument that is the name of an instance variable.

in contoller
@thing.save #=> fails due to errors

in view

error_messages_for “thing”

You can have as many calls to error_messages_for as you want in one
view,
for as many instance variables as you have.

The docs as www.rubyonrails.org/docs have more in depth explainations.
http://api.rubyonrails.org/classes/ActionView/Helpers/ActiveRecordHelper.html#M000460

Thanks.

I also got some other methods from google:

the errors are stored in the object @var.errors

Daniel ----- wrote:

On 9/27/06, Ianne L. [email protected] wrote:

hi,

I’ve a model with validates_*_of statements, but I have no idea how to
get the :message back, anyone has a clue? Thanks.

In your view you need to include the error_messages_for method. This
takes
a string argument that is the name of an instance variable.

in contoller
@thing.save #=> fails due to errors

in view

error_messages_for “thing”

You can have as many calls to error_messages_for as you want in one
view,
for as many instance variables as you have.

The docs as www.rubyonrails.org/docs have more in depth explainations.
http://api.rubyonrails.org/classes/ActionView/Helpers/ActiveRecordHelper.html#M000460

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs