OmniAuth / Rails - You have a nil object when you didn't expect it

匆匆过客 提交于 2019-12-06 11:19:10

It's probable that omniauth is nil. While you are checking for nil with unless onmniauth, the redirect_to doesn't actually stop the controller code below from executing.

You probably want something like this:

unless omniauth
  redirect_to authentications_url
  flash[:notice] = "Could not authenticate via #{params['provider']}."
  return
end

Now, you still need to figure out why omniauth is nil. For that, make sure you are using OmniAuth correctly by looking at the README. Is /auth/provider/callback routed to AuthenticationsController#create ?

I apologize in advance if you already know this method (you are a php developer after all).

Does rails support php style debugging similar to die() ? I have encountered weird incomprehensible error like this in both yii and kohana php frameworks.

What I do is put a die('AAAAA') at the end of the controller acion, and gradually move it up until IT gets triggered before the error does, that way I know exactly on what line the error was.

Then i move it into whatever function is called on that line and start again.

I don't know if rails supports this kind of raw debug style. Also it would help if the source code for those gems are in noncompiled code so you can insert die() all over the place like that.

You could do something like the equivalent of echo 'AAA'; exit; or something similar.

Also there is also the 'check if a function gets called: die('BBBBB'); :P

If you want to go really advanced there is also

die("AAAAA ".' '.__FILE__.'::Line:'.__LINE__);

This seemed to randomly fix itself. Go Rails!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!