简体   繁体   English

Rails validates_uniqueness_of错误消息不起作用

[英]Rails validates_uniqueness_of error message not working

Respected ppl ... 尊敬的人...

I have many models, one example is as below : 我有很多模型,一个例子如下:

class State < ActiveRecord::Base
  attr_accessible :state_name
  belongs_to :location
  validates_uniqueness_of(:state_name)
  validates_presence_of(:state_name)
end

i want to add error message globally for the uniqueness of attributes ... 我想为属性的唯一性全局添加错误消息...

en:
   hello: "Hello world"
   errors:
     messages:
          taken: "अद्वितीय होना चाहिए/Data Already Exists"  
          blank: "रिक्त नहीं किया जा सकता है/can't be blank"

The one for blank is working perfectly but the taken is still not working & i still get the default "has already been taken" error message ... 一个空白的工作正常,但采取仍然无法正常工作,我仍然得到默认的“已被采取”错误信息...

Kindly help ... 请帮助...

Sincere Regards -Sky 真诚的问候-天空

got it solved ... I replaced my en.yml file with the one provided here : raw.github.com/svenfuchs/rails-i18n/master/rails/locale/en.yml and replaced the "blank" and "taken" from this file as suited by me ... Everything is working now :D .... 解决了问题...我用下面提供的文件替换了我的en.yml文件:raw.github.com/svenfuchs/rails-i18n/master/rails/locale/en.yml并替换了“空白”和“已取用”从这个文件,我适合...现在一切都在工作:D ....

Regards -Sky 问候-天空

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM