Validations and :message

hey all,

nice that we can override the error message when a certain type of
validation fails by using :message. i’ve used this to help the user so
they can better understand why the app is rejecting their input (or
lack of input)… problem: the damn message comes up, but it prepends
the message with the fieldname .humanize’d !! I do not want that.
anybody know how to make it do what i want (just the message)??

thanks in advance and happy railsing (railling?) to all!

stuart (the other one)

I think, you can do this, but not with using validation helpers. I use
the following code (in model/ *.rb file), for example:

protected
def validate
errors.add({}, “The price should be positive.”) unless
self.price.nil? || self.price > 0.0
end

Sergey

write your own version of error_messages_for() . Just have a look at
the source of this Helper Method in the API,
it’s very simple …
instead of

Object.errors.fullmessages

just use

Object.errors.each {|attr, msg| …}

to loop though the errors and use only your defined messages without
the prepended Attribute name.

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