Here is the parent question: save the string to a file I want to pass a parameter that will be saved in a file (.csv) after clicking the button.
@bigtable - a table with rows 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 my code does not work: / I want to save @bigtable lines to a file. Each row entry in a table represents a new row in a file. And I want to save the file without redirecting the current page anywhere, but I donโt completely know why :( Please help.
Okay, I know why this does not work - I will add a new route to initialize the savefile method, but how to do it without redirecting / updating the current page with the results? Help plz
string file-io ruby-on-rails-3 save
mrmnmly
source share