rails 3中的errors.full_messages格式

xir*_*epe 15 ruby-on-rails

这里有一个小问题.

我的闪光通知/警报在里面 [" "]

在此输入图像描述

在我的控制器中,如果表单未保存,我必须显示错误.

format.html { redirect_to  new_project_procurement_management_plan_path, alert:"#{@project_procurement_management_plan.errors.full_messages}"}
Run Code Online (Sandbox Code Playgroud)

这是我将flash放入视图的方式:

_alert.html.erb:

<% [:notice, :error, :alert].each do |level| %>
  <% unless flash[level].blank? %>
    <div class="alert alert-<%= flash_class(level) %>" id="flash">
      <a class="close" data-dismiss="alert" href="#">×</a>
      <%= content_tag :p, flash[level] %>
    </div>
  <% end %>
<% end %>
Run Code Online (Sandbox Code Playgroud)

在我的帮助文件中:

#Flash Message

    def flash_class(level)
        case level
        when :notice then "success"
        when :error then "error"
        when :alert then "error"
    end
  end
Run Code Online (Sandbox Code Playgroud)

现在我如何删除里面的错误显示 [" "]

谁知道在哪里配置它?谢谢.

编辑

这是我模型中的验证消息:

def equality
    self.items.each do |item|
      errors.add(:base, "#{item.description.capitalize}: Quantity must be equal to the breakdown of quantity!") if item.months != item.qty
    end
  end
Run Code Online (Sandbox Code Playgroud)

roc*_*ist 33

errors.full_messages返回所有错误消息的数组,这就是您看到括号和引号的原因.您可以使用.to_sentence将该数组转换为可读的句子.

@project_procurement_management_plan.errors.full_messages.to_sentence