I have the following in my view:
<%= image_tag (url_for(:controller => 'app_images', :action => 'picture')) %>
The corresponding controller action is:
def picture
image = AppImage.create(:path => ("portrait3.jpeg"))
image.set_file_from_path
portrait = Magick::Image::from_blob(image.file)[0]
send_data portrait.to_blob, :type => "image/jpeg", :disposition => "inline"
end
And the model method for set_file_from_path is
def set_file_from_path
image = Magick::Image::from_blob(open(self.path).read)[0]
if image.rows > 400
resized = image.scale(400 * image.columns / image.rows, 400)
else
resized = image
end
self.file = resized.to_blob
end
For some reason, this image_tag doesn't render in Heroku, but renders locally, and I have the "portrait3.jpeg" file in my app/assets/images folder.
EDIT: I realized that I used create in heroku without actually connecting to S3 or anything else, which may not work as heroku doesn't allow for storage of a database on its servers I believe. I changed it to new and it still doesn't work.
So I did a few dumb things. Firstly, I forgot to require RMagick in the controller, and secondly I needed to do heroku run rake db:migrate.