0

我在 redmine 上创建了一个插件,它修改了 RepositoryControler 的核心。

我在这个控制器中添加了一个带有新函数的补丁,我可以根据角色权限调用这个函数。

但要正确设置权限,我需要为我的新功能配置before_filter授权 ( )。:authorize

问题是因为在我的补丁中添加 before_filter 不起作用,我不知道最好的方法是什么。按照我的代码:

客户端.rb

module RepositoriesPatch
    require_dependency 'repositories_controller'

    def self.included(base)
      base.send(:include, InstanceMethods)
    end
end

module InstanceMethods

  require_dependency 'repositories_controller'

  #I THINK THE BEFORE_FILTER SHOULD BE PLACED HERE, BUT IT DIDN'T WORKED.
  # before_filter :authorize, :only => :exec_client   (????????)

   def exec_client
    begin
     ....
    end

end

Rails.configuration.to_prepare do
  RepositoriesController.send(:include, RepositoriesPatch)
end

初始化.rb

  permission :repositories, :repositories => :exec_client

  project_module :repository do
    permission :exec, :repository => :exec_client
  end

  Rails.configuration.to_prepare do
    RepositoriesController.send(:include, RepositoriesPatch)
  end

  settings :default => {'empty' => true}, :partial => 'settings/gerar_versao_configuration'
end
4

2 回答 2

3

before_filter必须在类内部进行如下评估:

def self.included(base)
    base.send(:include, InstanceMethods)
    base.class_eval do
        unloadable
        before_filter :authorize, :only => :exec_client
    end
end
于 2013-10-24T21:10:47.740 回答
0

作为 Rails 4 中的一个旁白,引入了“before_action”,它显然会随着时间的推移取代“before_filter”

皮埃尔

于 2013-10-24T23:48:39.590 回答