index.html.erb
= form_for :file_upload, :html => {:multipart => true} do |f|
= f.label :uploaded_file, 'Upload your file.'
= f.file_field :uploaded_file
= f.submit "Load new dictionary"
模型
def file_upload
file = Tempfile.new(params[:uploaded_file])
begin
@contents = file
ensure
file.close
file.unlink # deletes the temp file
end
end
指数
def index
@contents
end
但是上传文件后,我的页面上没有打印任何内容= @contents