0

While trying to figure out how to get Carrierwave + Mongoid + gridfs to work in Padrino (Carrierwave + Mongoid + gridfs + Padrino admin image upload), I came across some Rails code that looks like it might do the job, if i can get it to work in Padrino.

Say you have a class that in rails extends ApplicationController, that you want available in padrino app + admin... where would you keep it and how would you declare it?

#app/controllers/gridfs_controller.rb
class GridfsController < ApplicationController

  def serve
    gridfs_path = env["PATH_INFO"].gsub("/upload/grid/", "")
    begin
      gridfs_file = Mongoid::GridFS[gridfs_path]
      self.response_body = gridfs_file.data
      self.content_type = gridfs_file.content_type
    rescue
      self.status = :file_not_found
      self.content_type = 'text/plain'
      self.response_body = ''
    end
  end
end

"serve" should be available in the main app as well as padrino admin.

Here's a repo with current state: https://github.com/bcsantos/debug

Community
  • 1
  • 1
bcsantos
  • 2,635
  • 5
  • 21
  • 22

1 Answers1

0

For reference after our chat in IRC, this might help https://gist.github.com/dariocravero/ab16044bb144bd52513a