Customized validation messages in Ruby on rails -


i have model called user.rb. model has customized email validation:

class user < activerecord::base   # include default devise modules. others available are:   # :token_authenticatable, :confirmable, :lockable , :timeoutable   devise :database_authenticatable, :registerable,          :recoverable, :rememberable, :trackable #,:validatable    # setup accessible (or protected) attributes model   attr_accessible :email, :password, :password_confirmation, :remember_me    validates_presence_of :email,:message=>"el campo email requerido"  end  

the problem browser shows "email el campo email requerido" while want "el campo email requerido" (without email before).

as rails newer 3.2.2, uses defined errors.format internationalization build validation full message.

i believe cannot change behavior 1 attribute, if want whole app, can follow answer on customise activemodel full_messages

one alternative define message directly record's base can printed is:

validate |user|   user.errors.add :base, 'el campo email requerido' if user.email.blank? end 

furthermore, pull request open provide solution on attribute level https://github.com/rails/rails/pull/14260


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -