我创建了一个表单来上传横幅图片,这是我控制器中的代码:
def banner_editprocess
uploaded_io = params[:banner]
if uploaded_io != nil && uploaded_io != ""
File.open(Rails.root.join('app','assets','images','banner', uploaded_io.original_filename), 'wb') do |file|
file.write(uploaded_io.read)
end
end
r = Banner.find(params[:id])
params.each do |k, v|
r[k] = v
end
if uploaded_io != nil && uploaded_io != ""
if r.banner != uploaded_io.original_filename
if r.banner != "" && r.banner != nil
File.delete(Rails.root.join('app','assets','images','banner', r.banner))
end
end
r.banner = uploaded_io.original_filename
end
这是我的观点:
= form_tag("/cms/servicepages/banner-edit-process", :multipart => true) do
%input{ :type => "hidden", :name => "id", :value => "#{@t.id}" }
%table
%tr
%th Banner Background
%td
%input{ :type => "file", :name => "banner", :value => "#{@t.banner}"}
当我尝试上传图片时,出现此错误:
can't convert ActionDispatch::Http::UploadedFile into String