2012-10-03 63 views
0

首先抱歉我的英語不好。 我已經安裝了cancan和bigbluebutton_rails, https://github.com/mconf/bigbluebutton_rails。 寶石bigbluebutton_rails有一些型號和控制器,例如 有bigbluebutton/servers_controller.rb。 此控制器有一些操作,如創建,加入,授權等。 我希望只有角色admin的用戶才能創建。 我能做什麼? 我需要將load_and_authorize_resource放在bigbluebutton/servers_controller.rb中? 但它是在寶石內,我認爲不建議修改寶石代碼。使用cancan與寶石控制器

回答

2

他們有一個頁面與康康舞整合:https://github.com/mconf/bigbluebutton_rails/wiki/How-to%3A-Integrate-with-CanCan

但嗯,還沒有被寫入...

所以...他們也有一個網頁設計與整合:https://github.com/mconf/bigbluebutton_rails/wiki/How-to%3A-Integrate-with-Devise已經被寫入,並且由此推斷,接受的方式將是繼承Bigbluebutton::ServersController

如何如下創建自定義服務器控制器:

class CustomServersController < Bigbluebutton::ServersController 
    load_and_authorize_resource! 
end 
+0

是的我認爲創建一個自定義控制器是唯一的方法,我必須改變代碼中原始控制器的所有引用。 – Mauro

+0

看起來好像是要走的路,是的,抱歉,我無法指出你更容易的事情! –

0

在Ruby中,你可以重新打開類,所以把一些代碼在/config/initializers/bigbluebutton.rb,說

require 'bigbluebutton' 

class Bigbluebutton::ServersController < ApplicationController 
    load_and_authorize_resource! 

    # you also have to overwrite this method so the @server loaded 
    # by CanCan is not overwritten by Bigbluebutton 
    def find_server 
    @server ||= BigbluebuttonServer.find_by_param(params[:id]) 
    end 
end 
0

作爲Sam Peacey的回答,現在BigbluebuttonRails有一個(相當簡單)的wiki頁面來描述如何將其與CanCan集成:https://github.com/mconf/bigbluebutton_rails/wiki/How-to:-Integrate-with-CanCan

您可以還使用應用程序Mconf-Web(https://github.com/mconf/mconf-web)作爲示例。當前在分支branch-v2https://github.com/mconf/mconf-web/tree/branch-v2)中的版本使用CanCan,Devise和BigbluebuttonRails,所有這些都在一起工作。