传递参数后保存文件 [英] saving file after passing parameter

查看:105
本文介绍了传递参数后保存文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是父级问题:将字符串保存到文件
我想传递的参数将被保存在文件(.csv)单击按钮后。



@bigtable是每行中有字符串的表。
这里是我的show.html.erb中的代码:

$ p $ ...一些代码在这里...
<%= form_tag do%>
<%text_field_tag,id =bigtable,value = @ bigtable.to_s%>
<%= submit_tag'Zapisz'%>
<%end%>

和我的控制器方法:

<$ p $
$ def






$ b $ File.open(path / to /文件,w){| file | file.write @ bigtable.join(\\\
)}
end

我的代码不起作用:/
我想保存@bigtable字符串到文件。该表的每一行记录都是该文件的新行。而我想保存文件,而不重定向当前页面的任何地方,但完全不知道为什么:(请帮助。






好的,我知道为什么它不工作 - 我要添加一些新的路线来初始化 savefile 方法 - 但是如何不重定向/刷新当前页面的结果?plz help 解决方案

我找到了一个解决方案 - 不写双重职位在这里是与主题的链接与答案:将变量保存到文件并下载它


Here is the parent question: save string to file I want to pass the parameter which will be saved in file(.csv) after clicking button.

@bigtable is a table with strings in each row. Here is the code in my show.html.erb:

...some code here...
<%= form_tag do %>
  <% text_field_tag, id = "bigtable", value = @bigtable.to_s %>
  <%= submit_tag 'Zapisz' %>
<% end %>

and my controller method:

 def savefile
    @bigtable = param[:bigtable]
    @bigtable.join("\n")
    File.open("path/to/file", "w") { |file| file.write @bigtable.join("\n") }
  end

But mine code doesn't work :/ I want to save @bigtable strings to file. Each row record of the table is a new line of the file. And I want to save file without redirecting current page anywhere but completely don't know why:( Please help.


okay, I know why it doesn't work - I shoud add some new route to initialize savefile method - but how do it without redirecting/refreshing current page with results? plz help

解决方案

I've found a solution - to not write double post here is the link to the topic with the answer: saving variable to file and downloading it

这篇关于传递参数后保存文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆