Search code examples
ruby-on-railsrubydeviseomniauthomniauth-google-oauth2

devise omniauth google oath error : undefined method `stringify_keys' for "/users/auth/google_oauth2":String


While using devise with omniauth-google-oauth2 gem there is a link generated in partials for Sign in with Google. The default code does not render links.

Here's the autogenerated snippet (to which I added some bootstrap based style)

<%- if devise_mapping.omniauthable? %>
  <%- resource_class.omniauth_providers.each do |provider| %>
    <%= link_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(resource_name, provider), class: "btn btn-block btn-social btn-google" do %>
        <span class="fa fa-google"></span>
    <%end%>
    <br />
  <% end -%>
<% end -%>

this doesn't work, I tried fiddle a bit and came up with

<%= link_to "Sign in with #{OmniAuth::Utils.camelize(provider)}",  user_google_oauth2_omniauth_authorize_path, class: "btn btn-block btn-social btn-google" do %> 
    <span class="fa fa-google"></span>
<%end%>

However none of the options work


Solution

  • Sorted, problem was in the way I am using the link, I changed it to a block because I wanted to use the Social Login Bootstrap buttons

    Note for myself and others who come to this post:

    When you convert link_to into a block, you do not give the link text argument, that text has to go in the block

    Here's the working version

    <%- if devise_mapping.omniauthable? %>
      <%- resource_class.omniauth_providers.each do |provider| %>
        <%= link_to omniauth_authorize_path(resource_name, provider), class: "btn btn-block btn-social btn-google" do %> 
            <span <span class="fa fa-google"></span> Sign in with <%=OmniAuth::Utils.camelize(provider)%>
        <%end%>
        <br />
      <% end -%>
    <% end -%>