require 'mime/types' class AttachmentController < ApplicationController # Use HubSsoLib for permissions management, as a layer on top of # the provision within RForum. @@hubssolib_permissions = HubSsoLib::Permissions.new({ :fetch => [ :admin, :webmaster, :privileged, :normal ] }) def AttachmentController.hubssolib_permissions @@hubssolib_permissions end def fetch id = @params[:id] file_path = Attachment.find(id).file_path mime_type = MIME::Types.type_for(file_path) || 'application/octet-stream' send_file file_path, :type => mime_type[0].content_type, :disposition => 'inline' rescue flash[:alert] = l(:attachment_not_found) if (@request.referer and @request.referer != '') redirect_to @request.referer else redirect_to :controller => '' end end end