2012-10-03 57 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,所有这些都在一起工作。