2012-10-15 27 views
2

我在rails 2中工作,我有一个模型级别的方法,我想在before_filter中调用。我怎样才能做到这一点? 我试过这种方法,但它不工作模型级方法调用before_filter

before_filter :LmsUser.can_edit_update, :only => [:new, :create, :edit, :update, :destroy] 
+0

LmsUSer是模型类的名称。 –

回答

3

你应该添加一个方法来你的控制器,并使用它作为前过滤器。例如:

class MyController < ApplicationController 
    before_filter :check_permissions, 
       :only => [:new, :create, :edit, :update, :destroy] 

    private 
    def check_permissions 
     unless LmsUser.can_edit_update 
     # redirect_to, render, or raise 
     end 
    end 
end 

有关更多信息,请参阅filters section of the Action Controller Overview guide