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"
Model
def file_upload
file = Tempfile.new(params[:uploaded_file])
begin
@contents = file
ensure
file.close
file.unlink # deletes the temp file
end
end
Index
def index
@contents
end
But nothing is getting printed in my page after I upload a file = @contents
Use file.read
to read the content of the uploaded file:
def file_upload
@contents = params[:uploaded_file].read
# save content somewhere
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With