【发布时间】:2011-12-29 23:31:26
【问题描述】:
我有以下控制器:
class CarsController < ApplicationController
autocomplete :user, :name
before_filter :require_user, :except => [:my_action]
def index
end
...
def my_action
end
end
我想只允许登录用户查看此控制器中的所有操作 - 这对我来说很好。但是my_action 的操作我希望每个人都可以访问 - 也适用于未登录的人。
我尝试使用:except 参数设置:before_filter,也使用:only 参数,但没有任何效果...该应用程序总是希望我登录...我还在做什么错了吗?
编辑:require_user 来自 application_controller.rb:
def require_no_user
logger.debug "ApplicationController::require_no_user"
if current_user
#store_location
flash[:warning] = "You must be logged out to access this page"
redirect_to account_url
return false
end
end
【问题讨论】:
-
require_user是什么?它是从哪里来的? -
也许这只是一个错字...但
dev my_action应该是def my_action...在您的实际代码中是这样输入的吗? -
另外,您的应用程序控制器中有过滤器吗?如果是这样,您需要在此控制器中跳过它。
-
@JustinM - 当然,在我的代码中是
def,而不是dev,这是我在输入此消息时犯的错误。 -
正如你的方法现在写的那样,如果有
current_user,它会返回false...这是你想要的吗?
标签: ruby authentication ruby-on-rails-3.1 before-filter