views:

18

answers:

1

If I have a text input name 'email', and if I set :message => 'Your email is wrong kind' the validation error message will have something like

'Email Your email is wrong kind.'

I am wondering if there is any way to remove that orginal input name (in above case, its Email) from the validation error output in rails3.

+1  A: 

There is probably a better way to do this, please let me know what it is, but this will work.

class User < ActiveRecord::Base
  validate do |user|
    user.errors.add_to_base("Your email is of the wrong kind") unless user.email =~ email_regexp
  end
end

An other hack-ish way to do this is to define a custom translation

# en.yml
en:
  activerecord:
    attributes:
      user:
        email: "Your email"

Combine this with :message => 'is wrong kind' and it should work. (although it's not really valid english ;) )

Maran