【发布时间】:2013-05-20 11:12:41
【问题描述】:
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后,我的页面上没有打印任何内容
【问题讨论】:
-
你是如何将
params[:uploaded_file]加入你的模型的?看起来像控制器代码
标签: ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-3.1 ruby-on-rails-3.2