rails3 customized error message

24 views
Skip to first unread message

Nadal

unread,
Sep 26, 2010, 12:40:05 PM9/26/10
to Ruby on Rails: Talk
In rails3 this is what I get.

validates_presence_of :subject
#=> subject can't be blank

validates_presence_of :subject, :message => "can't be empty"
#=> subject can't be empty

However What I want is
#=> Please enter title
even though the field name is "subject".

How do I do that in rails3?

Sunny Ezror

unread,
Sep 27, 2010, 5:31:36 AM9/27/10
to rubyonra...@googlegroups.com
Try this:

http://stackoverflow.com/questions/3755128/rails-3-custom-error-message-in-validation

I haven't played around with it, but object.errors[attribute] <<
error_message should probably be changed to just error_message.

Let me know how it goes.

-sunny
http://ezror.com
--
Posted via http://www.ruby-forum.com/.

radhames brito

unread,
Sep 27, 2010, 11:20:11 AM9/27/10
to rubyonra...@googlegroups.com

validates :subject , :presence => "Greetings sire, please introduce the title!"

am not sure if you need to put { }
Reply all
Reply to author
Forward
0 new messages