我在redmine上创建了一个插件,它修改了RepositoryControler的核心。
我在这个控制器中添加了一个带有新功能的补丁,我可以根据角色权限调用这个函数。
但要正确设置我需要为我的新功能配置before_filter
授权(:authorize
)的权限。
问题是因为在我的补丁中添加before_filter不起作用,我不知道这样做的最佳方式是什么。按照我的代码:
client.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
init.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
答案 0 :(得分:3)
before_filter
必须在课程内进行评估,如下所示:
def self.included(base)
base.send(:include, InstanceMethods)
base.class_eval do
unloadable
before_filter :authorize, :only => :exec_client
end
end
答案 1 :(得分:0)
作为Rails 4的一小部分介绍了“before_action”,显然随着时间的推移会取代“before_filter”
皮尔