听起来很简单吧?我在ApplicationController中有这个方法:
def authenticate_admin
redirect_to :root_path unless current_user.admin?
end
它在各种其他控制器中调用如下:
before_filter authenticate_admin
但是我得到一个错误,即应用该过滤器的方法中的任何实例变量都返回nil:
<% @expressions.each do |expression| %>
有什么想法?这对我来说似乎很奇怪。
答案 0 :(得分:1)
您是否将符号传递给过滤器?你需要传递一个符号。通过它的外观,你传递一个变量名称,它不存在。
before_filter :authenticate_admin # correct usage
您的示例显示了这一点:
before_filter authenticate_admin # incorrect
注意缺少的冒号。