Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
# config/initializers/carrierwave.rb
CarrierWave.configure do |config|
config.grid_fs_database = "database_name"
config.grid_fs_host = 'localhost'
config.grid_fs_access_url = "/uploads"
config.storage = :grid_fs
end
# app/metal/gridfs_serve_image.rb
require 'mongo'
require(File.dirname(__FILE__) + "/../../config/environment") unless defined?(Rails)
class GridfsServeImage
def self.call(env)
if env["PATH_INFO"] =~ /^\/uploads\/(.+)$/
begin
Mongo::GridFileSystem.new(Mongoid.database).open($1, 'r') do |file|
[200, { 'Content-Type' => file.content_type }, [file.read]]
end
rescue
[404, { 'Content-Type' => 'text/plain' }, ['File not found.']]
end
else
[404, { "Content-Type" => "text/html", "X-Cascade" => "pass" }, ["Not Found"]]
end
end
end
-# app/views/something/show.html.haml
= image_tag @something.photo.url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.