2
沒有使用before filter
在controller
我想檢查user
是否通過驗證,因爲它強制user
進行驗證。 我正在尋找一種方法如何在控制器中詢問user
是否已通過身份驗證,並基於此決定要從controller
返回哪些內容。Rails設計檢查沒有過濾器的驗證用戶
當前代碼:
class Api::TestsController < Api::ApiController
before_filter :authenticate_user!
// the filter is force me to be an authenticated user to get access to this controller
end
我想要什麼:
class Api::TestsController < Api::ApiController
def index
if current_user
// do something if the user is authenticated
else
// do something if the user not authenticated
end
end
end
我怎麼能實現呢? 我想要什麼:
class Api::TestsController < Api::ApiController
def index
if current_user then
// do something if the user is authenticated
else
// do something if the user not authenticated
end
end
end
我如何實現這一點?