I am working on an app that needs to return an image file in the controller.  I send over some request parameters to the app, it goes to the controller which pulls out the params and then creates an image based on those parameters.  So instead of rendering the view, the app would need to return a png file.  The send_data method was designed to do exactly this.  Here is the code:

data = File.open(your_image_path,’rb’).read
send_data(data , :filename => your_image_name, :type=>’image/png’)

Tags: ,