Ruby on rails Carrierwave文件上载不起作用-已保存零值
我正在尝试使用carrierwave在数据库中上载/保存图像。但是我的附件在数据库上没有持久化。表中仅存储名称字段 我指的是本教程: 经过彻底的研究,我尝试了几种不同的方法来改变强参数。但没有任何效果:( 在桌子上Ruby on rails Carrierwave文件上载不起作用-已保存零值,ruby-on-rails,carrierwave,image-uploading,Ruby On Rails,Carrierwave,Image Uploading,我正在尝试使用carrierwave在数据库中上载/保存图像。但是我的附件在数据库上没有持久化。表中仅存储名称字段 我指的是本教程: 经过彻底的研究,我尝试了几种不同的方法来改变强参数。但没有任何效果:( 在桌子上 #<ProjectImage id: 6, name: "Image 3", attachment: nil> 看法 参数 Parameters: {"utf8"=>"✓", "authenticity_token"=>"I+Q==", "project
#<ProjectImage id: 6, name: "Image 3", attachment: nil>
看法
参数
Parameters: {"utf8"=>"✓", "authenticity_token"=>"I+Q==", "project_image"=>{"name"=>"Image 3", "attachment"=>[#<ActionDispatch::Http::UploadedFile:0x0000000592c4d0 @tempfile=#<Tempfile:C:/Users/xx/AppData/Local/Temp/RackMultipart20160412-7900-1y69rwv.jpg>, @original_filename="jet.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"project_image[attachment][]\"; filename=\"jet.jpg\"\r\nContent-Type: image/jpeg\r\n">]}, "commit"=>"Save"}
[#<ActionDispatch::Http::UploadedFile:0x0000000592c4d0 @tempfile=#<Tempfile:C:/Users/STUART~1.MIN/AppData/Local/Temp/RackMultipart20160412-7900-1y69rwv.jpg>, @original_filename="jet.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"project_image[attachment][]\"; filename=\"jet.jpg\"\r\nContent-Type: image/jpeg\r\n">]
class ProjectImage < ActiveRecord::Base
mount_uploader :attachment, AttachmentUploader
end
参数:{“utf8”=>“✓", "真实性令牌“=>”I+Q==”,“项目图像”=>{“名称”=>“图像3”,“附件”=>[#]},“提交”=>“保存”}
[#]
类ProjectImage
AttachmentUploader类
class AttachmentUploader < CarrierWave::Uploader::Base
storage :file
uploader = AttachmentUploader.new
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
def extension_white_list
%w(jpg jpeg gif png)
end
end
类AttachmentUploader干杯从中删除多个:true使这项工作成功
干杯从中删除多个:true使此工作成功。
Parameters: {"utf8"=>"✓", "authenticity_token"=>"I+Q==", "project_image"=>{"name"=>"Image 3", "attachment"=>[#<ActionDispatch::Http::UploadedFile:0x0000000592c4d0 @tempfile=#<Tempfile:C:/Users/xx/AppData/Local/Temp/RackMultipart20160412-7900-1y69rwv.jpg>, @original_filename="jet.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"project_image[attachment][]\"; filename=\"jet.jpg\"\r\nContent-Type: image/jpeg\r\n">]}, "commit"=>"Save"}
[#<ActionDispatch::Http::UploadedFile:0x0000000592c4d0 @tempfile=#<Tempfile:C:/Users/STUART~1.MIN/AppData/Local/Temp/RackMultipart20160412-7900-1y69rwv.jpg>, @original_filename="jet.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"project_image[attachment][]\"; filename=\"jet.jpg\"\r\nContent-Type: image/jpeg\r\n">]
class ProjectImage < ActiveRecord::Base
mount_uploader :attachment, AttachmentUploader
end
class AttachmentUploader < CarrierWave::Uploader::Base
storage :file
uploader = AttachmentUploader.new
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
def extension_white_list
%w(jpg jpeg gif png)
end
end