Skip to content

Instantly share code, notes, and snippets.

@ilake
Created March 11, 2010 00:09
Show Gist options
  • Save ilake/328625 to your computer and use it in GitHub Desktop.
Save ilake/328625 to your computer and use it in GitHub Desktop.
You'll also need a controller to send the photo data when the image is requested by a web browser. This can be done all in one action with respond_to and an extra mime type. In environment.rb, declare the types of the images that you will be serving.
Mime::Type.register "image/jpeg", :jpg
Mime::Type.register "image/png", :png
def show
@photo = Photo.find params[:id]
respond_to do |format|
format.html
format.jpg do
send_data @photo.data, {
:disposition => "inline",
:type => "image/jpeg"
}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment