【问题标题】:A before_filter for Omniauth Facebook?Omniauth Facebook 的 before_filter?
【发布时间】:2013-05-21 18:42:52
【问题描述】:

对于设计,有一个非常易于使用的 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>

有什么想法吗?

【问题讨论】:

    标签: ruby-on-rails authentication omniauth


    【解决方案1】:

    找不到名为 auth 的变量。因此,您需要检查是否在某处初始化了 auth 变量。根据我的观点,OmniAuth Facebook gem 将经过身份验证的数据存储在请求环境中。请参考:https://github.com/mkdynamic/omniauth-facebook#auth-hash

    before_filter 将在服务请求之前执行。所以可能是导致问题的原因。

    希望对你有帮助!!!

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      • 刚试过:def authentication redirect_to :login unless User.find_by_provider_and_uid(omniauth.auth["provider"], omniauth.auth["uid"]),但得到相同的唯一未定义的局部变量或方法#<0x007f9fbf6d29d0>
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-01
      • 1970-01-01
      • 2015-04-20
      • 2016-09-23
      • 2014-05-23
      • 2012-03-05
      相关资源
      最近更新 更多