我正在编写一个redmine插件,需要向before_filter
添加一些已在redmine' IssuesController'
例如,
issues_controller.rb
class IssuesController < ApplicationController
before_filter :find_issue, :only => [:show, :edit, :update]
before_filter :find_issues, :only => [:bulk_edit, :bulk_update, :destroy]
before_filter :find_project, :only => [:new, :create, :update_form]
before_filter :authorize, :except => [:index]
end
我想向过滤器find_issue
和find_project
所以,在我的插件中,我将编写一个模块并将其包含在IssuesController
issues_controller_patch.rb
module IssuesControllerPatch
def self.included(base) # :nodoc:
base.send(:include, InstanceMethods)
base.class_eval do
before_filter :find_issue, :only => [:new_action1, :new_action2]
before_filter :find_project, :only => [:new_action1, :new_action2]
#prepend_before_filter :find_issue, :only => [:new_action1, :new_action2]
#prepend_before_filter :find_project, :only => [:new_action1, :new_action2]
end
end
module InstanceMethods
end
end
unless IssuesController.included_modules.include?(IssuesControllerPatch)
IssuesController.send(:include, IssuesControllerPatch)
end
这对我不起作用,因为它将它放在过滤器链的底部并执行了authorize
操作,授权是因为授权取决于project
。
我还尝试使用prepend_before_filter
并且它也无法正常工作,因为即使在user
从会话加载之前,它也会将其置于过滤器链的顶部。< / p>
那么,如何更新IssuesController
中定义的过滤器的操作列表?
Rails 3.2,Ruby 1.9.3,Redmine 2.6