Skip to content

Instantly share code, notes, and snippets.

@digitalronin
Created February 10, 2017 15:31
Show Gist options
  • Save digitalronin/f0237709d466b4d5774852011f8ee146 to your computer and use it in GitHub Desktop.
Save digitalronin/f0237709d466b4d5774852011f8ee146 to your computer and use it in GitHub Desktop.
class ImagesController < ApplicationController
skip_before_filter :ensure_logged_in
def show
id = "%s.%s" % [params[:id], params[:format]]
image = AdImage.find(id).decorate
send_data image.contents, :type => image.mimetype, :disposition => "inline"
rescue
render :text => ''
end
end
class AdImageDecorator < ApplicationDecorator
delegate_all
def mimetype
"image/%s" % file_suffix
end
private
def file_suffix
id.sub(/.*\./, '')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment