質問

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?

役に立ちましたか?

解決 2

In the end, I decided to encode my image in base64 and embed it in the view.

他のヒント

You can use after_filters in your controller to do any cleanup:

class YourController < ApplicationController
  after_filter :cleanup

  private

  def cleanup
    # clean it up
  end
end
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top