开发者

Omniauth issues in rails 3.1.0

I have followed a screen cast form ryan bates railscast and every thing is working fine except when i change my methods like as follows:

from

      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

to

  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>" + 开发者_StackOverflow社区e.backtrace.join("\n") + "</pre></body></html>"
    end

i keep getting undefined method stringify_keys' for "twitter":String but every thing works fine the first way. any ideas here


You have changed:

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

to:

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

You will get this error in any rails app as you are not specifying which fields to allocate the values to. An example (from one of my apps):

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

I think you meant the following:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜