Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 为Desive中的额外字段添加自定义错误消息_Ruby On Rails_Devise_Input Field - Fatal编程技术网

Ruby on rails 为Desive中的额外字段添加自定义错误消息

Ruby on rails 为Desive中的额外字段添加自定义错误消息,ruby-on-rails,devise,input-field,Ruby On Rails,Devise,Input Field,我正在开发一个Ruby on Rails应用程序,我正在使用Desive进行用户身份验证,我在表单中添加了一个额外的字段,现在我想为这个字段添加自定义错误消息(请输入格式为John#123的正确战斗标签),如果用户在字段中输入了错误的战斗标签格式 一些解决方案建议您在en.yml中添加消息,但我不知道在哪里进行更改 <div class="field"> <%= f.label :battletag %><br /> <%= f.t

我正在开发一个Ruby on Rails应用程序,我正在使用Desive进行用户身份验证,我在表单中添加了一个额外的字段,现在我想为这个字段添加自定义错误消息(请输入格式为John#123的正确战斗标签),如果用户在字段中输入了错误的战斗标签格式

一些解决方案建议您在en.yml中添加消息,但我不知道在哪里进行更改

   <div class="field">
    <%= f.label :battletag %><br />
    <%= f.text_field :battletag, autofocus: true, 
                  pattern: '[a-zA-Z]{1}[a-zA-Z0-9]{2,11}#[0-9]+',
                  placeholder: 'Johndoe#123'  %>
   </div>



我通常在模型中做类似的事情,所以我猜在
User.rb
中,假设您的模型名为
User

validates :battletag, format: { with: /[a-zA-Z]{1}[a-zA-Z0-9]{2,11}#[0-9]+/, :message => 'Please enter correct battletag with format John#123'}