Created
February 10, 2017 15:31
-
-
Save digitalronin/f0237709d466b4d5774852011f8ee146 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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