回形针找不到用于"file.jpg"的处理程序栏杆4 [英] paperclip No handler found for "file.jpg" rails 4
问题描述
我在其中一个应用程序中设置回形针gem时遇到问题.
尝试保存上传的文件时,出现No handler found for
错误消息.
I'm having problem with setting up paperclip gem in one of me apps.
I get No handler found for
error message when i try to save uploaded file.
我所做的事情
-
迁移:
migration:
add_attachment :orders, :file
型号:
model:
has_attached_file :file
validates_attachment_content_type :file, :content_type => /\Aimage\/.*\Z/
控制器:
controller:
def order_params
params.require(:order).permit(:file)
视图:
view:
form_tag url, method: :post, html: {multipart: true}
...
= file_field_tag 'order[file]', disabled: true, id: 'mtd_file',accept: 'image/png,image/gif,image/jpeg'
当我尝试在控制器Order.create params[order]
中执行时,出现错误
When I try to execute in my controller Order.create params[order]
I get error
未找到"file.jpg"处理程序
No handler found for "file.jpg"
当我查看order[file]
参数时,我看到它是一个字符串file.jpg
(上传文件的名称).
When I look into order[file]
param I see that it's a string file.jpg
(name of uploaded file).
推荐答案
尝试使用下面的代码行,您不必将mulitpart
作为html
哈希传递
Try using the below line of code, you don't have to pass mulitpart
as html
hash
form_tag url, method: :post, multipart: true
对于form_for
,您必须在html
哈希中传递multipart
For form_for
you have to pass multipart
in html
hash
form_for(@user), :html => { :multipart => true } do |f|
有关更多信息,您可以参考文档: RailsGuides-表单助手-5上传文件
For more info, you can refer to the documentation: RailsGuides - Form Helpers - 5 Uploading Files
这篇关于回形针找不到用于"file.jpg"的处理程序栏杆4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!