我在Ruby on Rails的Application中创建。一切都是英文的,但当我在字段中输入内容时,错误信息是德语。如何更改此消息的语言(英语)? 这是我的视图代码:
<%=form_for(@electricity_generation) do |f| %>
<% if @electricity_generation.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@electricity_generation.errors.count, "error") %>
prohibited this electricity_generation from being saved:</h2>
<ul>
<% @electricity_generation.errors.full_messages.each do |message| %>
<li>
<%=m essage %>
</li>
<% end %>
</ul>
</div>
<% end %>
<section>
<h2 align="center">
Chosen Scenario:
<%=link_to @scenario_selections, scenarios_path %>
</h2>
<br>
<div class="table-row-2">
<div align="center">
<div class="field">
<div class="table">
<strong>Information</strong>
</div>
<div class="table">
<strong>Value</strong>
</div>
<div class="table">
<strong>Positive Deviation (1=100%)</strong>
</div>
<div class="table">
<strong>Negative Deviation (1=100%)</strong>
</div>
<div class="table">
<%=label_tag(:annual_solar_irradiation, 'Annual Solar Irradiation (kwh/m^2):') %>
</div>
<div class="table">
<%=f.text_field :annual_solar_irradiation, type: "number", required: "required", placeholder: "kWh/m^2" %>
</div>
<div class="table">
<%=f.text_field :asi_max, type: "number", min: "0", max: "1", step: "0.01", required: "required"%>
</div>
<div class="table">
<%=f.text_field :asi_min, type: "number", min: "0", max: "1", step: "0.01", required: "required" %>
</div>
</div>
</div>
</div>
<div align="center">
<div class="actions">
<%=f .submit %>
</div>
</div>
</section>
<% end %>
这就是它的显示方式:
这是application.rb:
答案 0 :(得分:0)
您在表单中使用HTML constraint validation。您看到的错误消息是由浏览器创建的。浏览器以其安装的语言提供此错误消息。
如果需要,可以使用title
标记的input
属性覆盖(或添加信息;取决于浏览器)此消息。
<%=f.text_field :asi_max, type: "number", min: "0", max: "1", step: "0.01", title: "Please enter a number between 0 and 1.", required: "required" %>
如果您想完全控制此消息,则需要使用Javascript(另请参阅this问题)。有些库(如parsleyjs)可以帮助您实现这一目标。