Omniauth在rails 3.1.0中发布

时间:2011-09-04 11:53:36

标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.1 omniauth

我已经按照屏幕播放形式进行了ryan bates railscast,除非我改变我的方法,否则每件事情都会正常工作:

      def create
       omniauth = request.env["omniauth.auth"]
       current_user.authentications.create(:provider => omniauth['provider'], :uid =>         omniauth["uid"])
       flash[:notice] = "Authentication successful"
       rescue Exception => e
       # Just spit out the error message and a backtrace.
       render :text => "<html><body><pre>" + e.to_s + "</pre><hr /><pre>" +    e.backtrace.join("\n") + "</pre></body></html>"
    end

  def create
    omniauth = request.env["omniauth.auth"]
    current_user.authentications.create(omniauth['provider'], omniauth["uid"])
    flash[:notice] = "Authentication successful"
  rescue Exception => e
    # Just spit out the error message and a backtrace.
    render :text => "<html><body><pre>" + e.to_s + "</pre><hr /><pre>" + e.backtrace.join("\n") + "</pre></body></html>"
    end

我一直在使用未定义的方法stringify_keys' for "twitter":String,但是第一种方法都可以正常工作。这里的任何想法

1 个答案:

答案 0 :(得分:1)

您已更改:

current_user.authentications.create(:provider => omniauth['provider'], :uid =>         omniauth["uid"])

为:

current_user.authentications.create(omniauth['provider'], omniauth["uid"])

您将在任何rails应用中收到此错误,因为您没有指定要为其分配值的字段。 一个例子(来自我的一个应用程序):

ruby-1.9.2-p180 :002 > User.create("a", "b")
NoMethodError: undefined method `stringify_keys' for "a":String

我认为你的意思如下:

user = User.find_by_provider_and_uid(auth["provider"], auth["uid"]) || User.create_with_omniauth(auth)