我试图验证附件的扩展名。我试着用下面的:Rails验证附件扩展
validates_format_of :image_vector, :with => %r{\.(ai|dxf|eps|svg)$}i
但似乎工作,每当我上传SVG文件它说,格式不正确不。我也尝试使用回形针,但似乎无法使用扩展。 任何帮助,将greately赞赏
我试图验证附件的扩展名。我试着用下面的:Rails验证附件扩展
validates_format_of :image_vector, :with => %r{\.(ai|dxf|eps|svg)$}i
但似乎工作,每当我上传SVG文件它说,格式不正确不。我也尝试使用回形针,但似乎无法使用扩展。 任何帮助,将greately赞赏
validates_format_of :image_vector, :with => %r{\.(ai|dxf|eps|svg)$}i, :message => "whatever"
这就是我已经拥有的代码:/ –
当我发布我的解决方案时,您没有在期限之前错过\。 – Magicmarkker
尝试使用我发布的新代码。粘贴你得到的任何错误。 – Magicmarkker
用回形针,你可以做这样的事情:
before_post_process :is_image?
def is_image?
["image/jpeg", "image/pjpeg", "image/png", "image/x-png", "image/gif"].include?(self.plan_content_type)
end
也许你可以在你的环境中尝试。
它是否返回任何错误? –