如何将操作推送到已定义的before_filter?

时间:2014-12-11 05:46:12

标签: ruby-on-rails ruby ruby-on-rails-3 redmine redmine-plugins

我正在编写一个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_issuefind_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

0 个答案:

没有答案