1

对于设计,有一个非常易于使用的 Before_filter 在控制器中使用。

出于某种原因,我无法让它为 Omniauth_facebook Gem 工作。我在 Facebook Omniauth 上关注 Railscast

 before_filter :authenticate

  def authenticate
   redirect_to :login unless User.find_by_provider_and_uid(auth["provider"], auth["uid"])
 end
 end

但我收到一个错误:

   NameError in PostsController#new

    undefined local variable or method `auth' for #<PostsController:0x007f9fbfa7ee58>

有什么想法吗?

4

2 回答 2

0

我认为您所追求的 auth 变量是 request.env["omniauth.auth"]

于 2013-05-28T08:30:37.937 回答
0

It can't find the variable named auth. So you need to check that auth variable initialized somewhere or not. As per my view, OmniAuth Facebook gem is storing the authenticated data in request env. Please refer this: https://github.com/mkdynamic/omniauth-facebook#auth-hash.

before_filter will execute before serving the request. so may be that causes the issues.

Hope that helps!!!

于 2013-05-21T19:03:00.440 回答