请教上传文件到本地文件夹的问题,谢谢
class Myfile < ActiveRecord::Base
def file=(file_field)
File.open( "#{RAILS_ROOT}/myfile ", "wb+ ") do |f|
f.write(file_field.read)
end
end
end
class UploadController < ApplicationController
def upload
unless request.get?
p params[:file]
file = Myfile.new(params[:file])
if file.save
render :text => "OK "
else
render :text => "FAIL "
end
end
end
end
上传文件到本地文件夹,为什么总提示「数据库没有myfiles表」这个信息?必须要建表么?
[解决办法]
params[:file]
你的页面需要一个 <input type= "file " name= "file " id= "file ">