class ApplicationController < ActionController::Base # ... def serve_attachment(model, filename) case RAILS_ENV when 'development' redirect_to model.attachment_url(filename) when 'production' response.headers['Content-Type'] = model["_attachments"][filename]['content_type'] response.headers['Content-Disposition'] = "inline; filename=#{filename}" response.headers['X-Accel-Redirect'] = "/couch/#{model.id}/#{filename}" render :nothing => true else metadata = model["_attachments"][filename] data = model.fetch_attachment(filename) send_data(data, { :filename => filename, :type => metadata['content_type'], :disposition => "inline" }) end end end