我能够使用自定义 Ckeditor 控制器解决此问题,并从此处获得一些指导:
https://github.com/galetahub/ckeditor/issues/246
首先我需要复制 Ckeditor 控制器 pictures_controller.rb 和 attachment_files_controller.rb 并将它们放在这里:
/app/controllers/ckeditor/
然后对他们的更新index 的建议进行一些更新是必要的,特别是picture_model.find_all 需要在pictures_controller.rb 中为picture_adapter.find_all(类似地attachment_file_adapter.find_all 在attachment_files_controller .rb)
这一切的关键是设置适当的范围:ckeditor_pictures_scope(assetable_id: ckeditor_current_user) & ckeditor_attachment_files_scope(assetable_id: ckeditor_current_user)
一旦这些修订到位,图片和附件的文件浏览器将只显示该用户的适当文件。
这是修改后的文件...更改都在第 4 行。
/app/controllers/ckeditor/pictures_controller.rb
class Ckeditor::PicturesController < Ckeditor::ApplicationController
def index
@pictures = Ckeditor.picture_adapter.find_all(ckeditor_pictures_scope(assetable_id: ckeditor_current_user))
@pictures = Ckeditor::Paginatable.new(@pictures).page(params[:page])
respond_with(@pictures, :layout => @pictures.first_page?)
end
def create
@picture = Ckeditor.picture_model.new
respond_with_asset(@picture)
end
def destroy
@picture.destroy
respond_with(@picture, :location => pictures_path)
end
protected
def find_asset
@picture = Ckeditor.picture_adapter.get!(params[:id])
end
def authorize_resource
model = (@picture || Ckeditor.picture_model)
@authorization_adapter.try(:authorize, params[:action], model)
end
end
/app/controllers/ckeditor/attachment_files_controller.rb
class Ckeditor::AttachmentFilesController < Ckeditor::ApplicationController
def index
@attachments = Ckeditor.attachment_file_adapter.find_all(ckeditor_attachment_files_scope(assetable_id: ckeditor_current_user))
@attachments = Ckeditor::Paginatable.new(@attachments).page(params[:page])
respond_with(@attachments, :layout => @attachments.first_page?)
end
def create
@attachment = Ckeditor.attachment_file_model.new
respond_with_asset(@attachment)
end
def destroy
@attachment.destroy
respond_with(@attachment, :location => attachment_files_path)
end
protected
def find_asset
@attachment = Ckeditor.attachment_file_adapter.get!(params[:id])
end
def authorize_resource
model = (@attachment || Ckeditor.attachment_file_model)
@authorization_adapter.try(:authorize, params[:action], model)
end
end