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
savefile
is getting called? – Tellerform_tag
and a route so that you'll actually end up on thesavefile
action in the controller when clicking the button. – Ordure