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 Ruby on Rails — A web-app framework that includes everything needed to create database-backed web applications according to the Model-View-Controller (MVC) pattern. 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 Ruby on Rails — A web-app framework that includes everything needed to create database-backed web applications according to the Model-View-Controller (MVC) pattern. have more in depth explainations.
http://api.rubyonrails.org/classes/ActionView/Helpers/ActiveRecordHelper.html#M000460