0
我試圖創建一個表單,將PDF和圖像上傳到目錄。目前,我有這個代碼,我已經複製過一個工作示例:Rails窗體上傳文件到目錄 - 未定義的方法
def resources_addprocess
r = Resource.new
r.title = params[:title]
r.reference = params[:reference]
r.description = params[:description]
r.campaign = params[:campaign]
r.resourcetype = params[:resourcetype]
uploaded_io = params[:file]
File.open(Rails.root.join('public','resources', uploaded_io.original_filename), 'wb') do |file|
file.write(uploaded_io.read)
end
if params[:preview].present?
uploaded_io2 = params[:preview]
File.open(Rails.root.join('app','assets','images','preview', 'resources', uploaded_io2.original_filename), 'wb') do |file|
file.write(uploaded_io2.read)
end
r.preview = uploaded_io2.original_filename
end
r.file = uploaded_io.original_filename
if r.save
flash[:success] = "You successfully added a resource."
redirect_to "/cms/resources"
else
flash[:error] = "resource wasn't successfully."
redirect_to "/cms/resources"
end
end
,但我得到了以下錯誤:undefined method 'original_filename'
這個工作在不同的項目..不知道它爲什麼不呢?