【发布时间】:2017-05-17 16:55:50
【问题描述】:
我正在使用 Rails 5。在我的模型中,如果我的某个字段无效,我会设置一个错误...
errors.add(:my_field, 'The field is not in the correct format')
然后在我看来,我会像这样显示错误...
<% if !@user.errors[:my_field].empty? %><span class="profileError"> <%= @user.errors[:my_field] %></span><% end %>
显示错误时,显示为
["The field is not in the correct format"]
如何去掉出现在错误周围的括号?这似乎是一个非常简单的问题,但我不知道这些东西是如何潜入其中的。
【问题讨论】:
-
把这个
@user.errors[:my_field]改成@user.errors[:my_field].first
标签: ruby-on-rails validation model ruby-on-rails-5