Reputation: 558
I am building an application that makes a lot of API calls. I would like to be able to write the output of each API call to a file and then be able to download that file. So far this is what my controller looks like:
def show
@resp = Faraday.get("https://my_api_endpoint")
end
How can I write a string to a file and download that file with Ruby on Rails?
Upvotes: 0
Views: 278
Reputation: 1022
Your question is too vague.
You can write to file this way:
File.write(Rails.root.join("PATH_TO_FILE.txt"), @resp.to_s, mode: "a")
But you should attach a file to your model to be able to retrieve it later e.g.
has_one_attached :response_txt
Upvotes: 1