【问题标题】:Content_type error displaying twiceContent_type 错误显示两次
【发布时间】:2014-03-25 23:34:09
【问题描述】:

我收到两次内容类型错误消息,如何删除第二个?

Document content type is not an acceptable type of document only pdf
Document ["is not an acceptable type of document only pdf"]

我试过这样做(就像我在其他帖子中看到的那样):

  @document.errors.delete(:document)

但它消除了这两个错误。这是我用于验证的代码:

  validates_attachment_content_type :document, :content_type => ["application/pdf"], :message => 'is not an acceptable type of document only pdf'

这是我用来显示错误的代码

发生错误
<ul class="ml-30">
    <% @errors.full_messages.each do |message| %>
        <li><%= message %></li>
    <% end %>
    <li>Please change a few things up and try submitting again.</li>
</ul>

我怎样才能不只显示正确的错误消息?

【问题讨论】:

  • 这是验证...但是您用来显示错误的代码在哪里?另外 - 这是什么validates_attachment_content_type 验证?这是你从某个图书馆得到的方法吗?因为它肯定不是标准的 Rails 验证 :) 如果您可以向我们展示该代码 - 也许我们可以修复它。
  • @Flezcano 你能分享你显示错误的视图代码吗?
  • 谢谢,查看编辑

标签: ruby-on-rails


【解决方案1】:

删除 :message 部分,这样就可以了。

validates_attachment_content_type :document, :content_type => ["application/pdf"]

第一条消息仍然存在。

【讨论】:

  • 感谢您的回答。我按照你说的做了,现在我收到第一个错误,另一个错误说“文档 [无效]”
  • 以下是删除该消息的方法。 stackoverflow.com/a/3707274/1905235
猜你喜欢
  • 1970-01-01
  • 2011-09-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多