2013-04-25 51 views
0

我在我的Rails應用程序中使用了ckeditor。它工作得很好,但我沒有設法讓照片上傳/眉毛/發送到服務器工作!跳過CKeditor認證?

我使用康康舞和我得到CanCan::AuthorizationNotPerformed at /pictures, 即使在配置/初始化/ ckeditor.rb註釋掉config.authorize_with :cancan

,所以我想大約在取消config.authorize_with :cancan,然後用skip_authorization_check,但我不知道在哪裏使用它!對軌道是新的。

我幾乎想盡一切辦法!

任何幫助/線索/技巧請嗎?

+0

你的ability.rb是怎麼樣的? – Mattherick 2013-04-25 17:08:01

回答

0

看着寶石的ckeditor/pictures_controller.rb讓你知道如何解決這個問題。 (使用bundle open ckeditor從您的應用程序的根目錄,然後導航到app/controller/ckeditor/

因此,在您對內容的Rails應用程序創建一個ckeditor/pictures_controller.rb

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_resourceauthorize_resourcecreate方法,您將可以上傳圖片。

當您想刪除上傳的圖像時,destroy方法會被調用。