查看ckeditor/pictures_controller.rb
gem 可以让您了解如何解决问题。(bundle open ckeditor
从应用程序的根目录使用,然后导航到app/controller/ckeditor/
)
ckeditor/pictures_controller.rb
因此,在您的 Rails 应用程序中创建一个包含以下内容的应用程序:
class Ckeditor::PicturesController < Ckeditor::ApplicationController
load_and_authorize_resource
def create
@picture = Ckeditor::Picture.new
respond_with_asset(@picture)
end
def destroy
@picture.destroy
respond_with(@picture, :location => pictures_path)
end
protected
def authorize_resource
model = (@picture || Ckeditor::Picture)
@authorization_adapter.try(:authorize, params[:action], model)
end
end
这个解决方案的关键是load_and_authorize_resource
and方法authorize_resource
,create
你就可以上传图片了。
destroy
当您要删除上传的图像时,将调用该方法。