2011-12-29 32 views
1

我有以下控制器:混淆有关的函数:的before_filter

class CarsController < ApplicationController 
    autocomplete :user, :name 
    before_filter :require_user, :except => [:my_action] 

    def index 
    end 

    ... 

    def my_action 
    end 
end 

我希望让看到这个控制器的所有动作只为登录的用户 - 这工作我的罚款。不过,我想行动my_action有入店为大家 - 也为人们谁不登录

我试图设置:before_filter:except参数,还与: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 
+0

那是什么'require_user'?它来自哪里? – 2011-12-29 23:33:14

+0

我更新了我原来的帖子。 – user984621 2011-12-29 23:36:33

+1

也许这只是一个错字......但是'dev my_action'应该是'def my_action' ......是它如何在你的实际代码中输入? – Slick23 2011-12-29 23:37:17

回答

1

使用 skip_before_filter:require_user,:只=> [:my_action]