变量保存到文件,并下载它 [英] saving variable to file and downloading it
问题描述
我有一个问题,我的previous问题。没有人能不能帮助我,所以我会努力写出更好的这个时候,我想要什么:
I've got a problem with my previous question. Nobody can't help me so I'll try to write better this time what I want:
- 我有一个
发电机#秀
视图,该视图我想要做的
无需刷新页面一切单击按钮后等。 - 我有一个变量(它无处存储 - 只是动态穿上
该网站):@bigtable
,这实际上是一个字符串数组 - 我放在这个视图按钮:
<%=的form_tag DO%GT;<%= submit_tag保存它%><%结束%GT;
- 如果有人将那个按钮点击我要弹出一个窗口,
他可以设在那里,他要保存一个txt文件(文件名设置)
摆满了@bigtable
阵列记录。
- I've got a
generators#show
view, and in this view I want to do everything without refreshing page after clicking a button etc. - I've got a variable (it is nowhere stored - just dynamically put on
the site):
@bigtable
, which is actually an array of strings - I have a button placed in this view:
<%= form_tag do %><%= submit_tag 'Save it' %><% end %>
- If someone will click on that button I want to pop up an window and
he could set where he want to save a txt file (and set filename),
filled with all
@bigtable
array records.
有关几天我想我已经尝试了一切,但我真的不明白怎么解决它。可能有人,请写在这里,我应该写什么方法,模型和控制器?和所有必需的路线?我会真的AP preciate任何帮助。
我的previous线程(但请不要给我有还是给像有相同的答案):通过参数后保存文件
For couple days I think I've tried everything but I don't really understand how to solve it. Could someone, please write here what methods in model and controller I should write? And all required routes? I'll really appreciate any help. My previous thread (but please do not send me there or give same answers like there): saving file after passing parameter
推荐答案
终于我找到了一个解决方案:
finally I've found a solution:
def savefile
@generator = Generator.new(params[:generator])
@bigtable = Rails.cache.read("pass")
doc = "wyniki.csv"
File.open(doc, "w"){ |f| f << @bigtable}
send_file(doc, :type => 'text; charset=utf-8')
end
这篇关于变量保存到文件,并下载它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!