Forum: Ruby on Rails Custom error messages

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
57577e3dcdf1ce1fbc38bd5df21e57b4?d=identicon&s=25 Fernando Macedo (fmk)
on 2006-05-02 04:23
On a model I have the following simple validator:

def validate
  unless name && name =~ /^\w+$/
    errors.add_to_base("Name is missing")
  end
end

I would like to display a custom message on my views, without using the
helper <%= error_messages_for "table" %>

Where the messages from errors.add_to_base are stored and how to access
them in the views?
3d7e63cfdded1786a6526f52478e6ea6?d=identicon&s=25 Joe Clarke (Guest)
on 2006-05-03 19:05
(Received via mailing list)
Fernando,

> Where the messages from errors.add_to_base are stored and how to access
> them in the views?
ActiveRecord stores them in an array. There are several ways you can
get to these for example object.errors.full_messages will return an
array of the full error messages. You may also want to read the
following page from the API
http://api.rubyonrails.org/classes/ActiveRecord/Errors.html

--
Joe Clarke
RailsPlayground.com
This topic is locked and can not be replied to.