Mat*_*ieu 2 ruby-on-rails attachment paperclip
当我尝试上传不在的文件时,我系统地出错了 ["image/jpg", "image/jpeg", "image/gif", "image/png", "image/pjpeg", "image/x-png"]
当我尝试上传像'wav'这样的文件时,我收到了这条消息
* Photo /var/folders/nT/nTr21TWfFRO7r3cyG-h-7++++TM/-Tmp-/Clip audio 01,39154,0.wav is not recognized by the 'identify' command.
* Photo /var/folders/nT/nTr21TWfFRO7r3cyG-h-7++++TM/-Tmp-/Clip audio 01,39154,0.wav is not recognized by the 'identify' command.
* Photo content type Accepted files include: jpg, gif, png
因此,它检测到该文件不是图像并显示我的消息,"Accepted files include: jpg, gif, png"但我有这个额外的消息包括在我的照片无法通过'识别'命令识别...上传工作正常的图片
我的代码是:
控制器:
def upload
@picture= Picture.new(params[:picture])
if !@picture.valid?
render :form
end
end
Run Code Online (Sandbox Code Playgroud)
查看表格:
<%= error_messages_for :picture, :header_message => nil, :message => nil %>
<% form_for :picture, @picture, :name => "uploadPic", :url => { :action => 'upload_data'}, :html => {:name => 'uploadForm', :multipart => true } do |form| %>
<%= form.file_field :photo %>
<%= submit_tag 'Save'%>
<% end %>
Run Code Online (Sandbox Code Playgroud)
图片型号:
class Picture < ActiveRecord::Base
require 'paperclip'
has_attached_file :photo, :styles => { :medium => "300x300>", :thumb => "100x100>" }
validates_attachment_size :photo, :less_than => 2.megabytes , :message => "must be less than 2 megabytes"
validates_attachment_content_type :photo, :content_type => ["image/jpg", "image/jpeg", "image/gif", "image/png", "image/pjpeg", "image/x-png"], :message => "Accepted files include: jpg, gif, png"
end
Run Code Online (Sandbox Code Playgroud)
解决了它:whiny => false
has_attached_file:photo,:whiny => false,:styles => {:medium =>"300x300>",:thumb =>"100x100>"}
| 归档时间: |
|
| 查看次数: |
3559 次 |
| 最近记录: |