[Rails] The Cause of redirect_to Not Working Was a Half-Width Space in the URL
I was using Rails’ redirect_to method to handle redirects after Facebook authentication, but it wasn’t working properly and I was troubled.
The cause of the redirect not working was that there was a half-width space in the URL…
redirect_to @facebook_cookies.url_for_oauth_code(:permissions => "publish_stream, read_stream")
#redirect_to 'https://graph.facebook.com/oauth/authorize?client_id=125635350871368&redirect_uri=http://localhost:3000/&scope=publish_stream, read_stream'
It seems the redirect wasn’t working because of the half-width space in the “publish_stream, read_stream” part.
I accidentally wrote it in a way that would pass an array when it should be passed as a string…
The correct way is to specify the permissions passed to scope without spaces, as follows:
redirect_to @facebook_cookies.url_for_oauth_code(:permissions => "publish_stream,read_stream")
#redirect_to 'https://graph.facebook.com/oauth/authorize?client_id=125635350871368&redirect_uri=http://localhost:3000/&scope=publish_stream,read_stream'
By the way, I’m using the koala library for using the Facebook API.
That’s all from the Gemba.