Rails 3, Validates, Custom Message

In Rails < 3, I could have a validation on model such as:

validates_presence_of :name, :message => "some custom message here"

If I try something similar in Rails 3:

validates :name, :presence => true , :message => "some other custom
message"

obviously, it throws an exception. So the question is, in Rails 3, how
to you give a simple custom message? Do I need to go through and set up
a custom validation class for each validation, just to show a different
message? I've looked at:

http://www.railsapi.com/doc/rails-v3.0.0/classes/ActiveModel/Validations/ClassMethods.html#M003721

but it seems to show that a custom class would need to be set up for
each attribute of my models? I'm sure there's a shortcut, but have yet
to find it.

Thanks.

v

radhames brito wrote:

validates :name, :presence => {"some other custom"}

most options are now passed like that , for example

validates :name, :unique => {:scope => :company_id}

you see, options are now passed as hashes to the validation key

Yeah, I did see that, but I don't see any options for what I want to do.
The syntax you gave, however throws a syntax error.

Hello John,

In Rails 3 also validates_presence_of is present. Why you are not using this one?

validates_presence_of :name, :message => “some custom message here”

Thanks!

Butu

Hello.

Try this:

validates :name, :presence => { :message => "My custom message" }

Butu wrote:

Hello John,

In Rails 3 also validates_presence_of is present. Why you are not using
this
one?

  validates_presence_of :name, :message => "some custom message here"

Thanks!
Butu

Hi,

I am aware the original version is available, but I was trying to update
to the new validators in Rails 3. I guess I'm going to just have to
ditch that and go back to the old. Seems to be another "New and Shiny"
way of doing things, but lose simple functionality... :wink:

validates :name, :presence => { :message => “hello world” }

what is it you want to do ?

Radhames Brito wrote: