Reputation: 685
I would like to write some user-generated data to a CSV file in production in Rails, but I have been unable to successfully write and obtain the data. It is possible that it is not being written, or that my method of trying to obtain it is flawed (or both).
This is in my static pages controller:
def home
line = ["static_pages","home","test"]
CSV.open("db/output.csv", "ab") do |csv|
csv << line
end
...
end
I've tried two ways of viewing the production version of the output.csv
file, both with the same result.
Method #1:
$ heroku run console
> Dir.chdir("db")
> puts CSV.open("output.csv").read()
Method #2
$ git fetch
$ git checkout FETCH_HEAD -- db/output.csv
Both methods return the version of the file that was most recently updated while in the development environment.
I could easily be missing something fundamental here. Please let me know what you think may be the issue.
Upvotes: 0
Views: 239
Reputation: 12818
You should not rely on Heroku filesystem. https://devcenter.heroku.com/articles/dynos#ephemeral-filesystem . Consider it as "read-only" and try to use another method to store data (database for instance).
Upvotes: 1