相关疑难解决方法(0)

在RoR 4中使用验证的正则表达式

有以下代码:

class Product < ActiveRecord::Base
  validates :title, :description, :image_url, presence: true
  validates :price, numericality: {greater_than_or_equal_to: 0.01}
  validates :title, uniqueness: true
  validates :image_url, allow_blank: true, format: {
      with: %r{\.(gif|jpg|png)$}i,
      message: 'URL must point to GIT/JPG/PNG pictures'
  }
end
Run Code Online (Sandbox Code Playgroud)

它有效,但是当我尝试使用"rake test"测试它时,我会收到这条消息:

rake aborted!
The provided regular expression is using multiline anchors (^ or $), which may present a security risk. Did you mean to use \A and \z, or forgot to add the :multiline => true option?
Run Code Online (Sandbox Code Playgroud)

这是什么意思?我该如何解决?

ruby activerecord ruby-on-rails

83
推荐指数
2
解决办法
3万
查看次数

标签 统计

activerecord ×1

ruby ×1

ruby-on-rails ×1