0
這裏是我的代碼:驗證錯誤。這裏有什麼問題?
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: 'must be a URL for GIF, JPG, or PNG image.'
}
end
這裏是我收到的錯誤:
所提供的正則表達式使用多錨(^或者$),這可能會帶來安全風險。你的意思是使用\ A和\ z,還是忘了添加:multiline => true選項?
第5行
顯然存在錯誤時,我感到非常新的Rails。實際上,這是我的第一天。有什麼問題,我該如何解決它?謝謝你的時間。
答案出現在您的錯誤消息中:在'with::'中使用'\ z'而不是'$'。 –
非常感謝。 –