Reputation: 123
For my Rails app, I have a controller that generates a single-use temporary image that the corresponding view needs to load. I am currently using Tempfile for this, but the problem is that the file is sometimes garbage collected before the view has a chance to load it.
I have considered using File with the Maid gem or a cron job to clean up the images on a periodic basis, but would prefer a cleaner solution.
For example, is there a built-in page load callback concept in Rails that would allow me to call a helper method after the view finishes rendering?
Upvotes: 0
Views: 228
Reputation: 123
In the end, I decided to encode my image in base64 and embed it in the view.
Upvotes: 0
Reputation: 13541
You can use after_filter
s in your controller to do any cleanup:
class YourController < ApplicationController
after_filter :cleanup
private
def cleanup
# clean it up
end
end
Upvotes: 1