Ruby on rails 回形针:;具有与其内容不匹配的扩展名“;错误
我只是想用回形针上传一些非常简单的图片。我在谷歌上搜索了这个问题,似乎每个人都有比简单上传更复杂的问题。下面是我的模型和控制器 pin.rbRuby on rails 回形针:;具有与其内容不匹配的扩展名“;错误,ruby-on-rails,paperclip,Ruby On Rails,Paperclip,我只是想用回形针上传一些非常简单的图片。我在谷歌上搜索了这个问题,似乎每个人都有比简单上传更复杂的问题。下面是我的模型和控制器 pin.rb class Pin < ActiveRecord::Base belongs_to :user has_attached_file :image validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/ # validates the descri
class Pin < ActiveRecord::Base
belongs_to :user
has_attached_file :image
validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/
# validates the description
validates :description, presence: true
validates :user_id, presence: true
# validates paperclip
validates_attachment :image, presence: true,
content_type: { content_type: ["image/jpeg", "image/jpg", "image/png", "image/gif"]},
size: { less_than: 5.megabytes }
end
这是使用强参数添加:image的正确方法吗?在rails 3中,他添加了:image在attr\u accessible
Second,在回形针自述中,它说我应该运行,转换,并最终在配置文件中输入这一行
Paperclip.options[:command_path] = "/usr/local/bin/"
因为我使用的是一台windows机器,这是我经过数小时寻找答案后最终得到的结果
Paperclip.options[:command_path] = "C:/Program Files/ImageMagick-6.8.9-Q16/"
上述路径对于windows是否相对正确 在pin.rb中删除此行
validates_attachment :image, presence: true,
content_type: { content_type: ["image/jpeg", "image/jpg", "image/png", "image/gif"]},
size: { less_than: 5.megabytes }
因为你已经在用了
validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/
我还和你们一样,用过时的视频制作了一个Rails。
检查我的项目中的错误
这里是链接
祝你好运 我也使用Windows,并收到此错误。我找到了答案。据我所知,回形针通过让服务器的操作系统验证文件的MIME类型来防止欺骗。它通过执行以下命令来执行此操作:
file -b --mime <my_file_name.extension>
file-b--mime
问题是,标准Windows命令行没有文件
命令,因此欺骗检查失败,回形针抛出您观察到的错误
要解决这个问题:
PATH
变量,使其包含“Windows文件”bin
目录路径。(对我来说,这是C:\ProgramFiles(x86)\GnuWin32\bin
)PATH
变量,请重新启动命令行、Git Bash或其他命令文件
命令validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/
file -b --mime <my_file_name.extension>