如何更改提供商的名称

时间:2017-04-11 20:46:50

标签: ruby-on-rails ruby

我有一个网站与Omniauth使用设计宝石,一切正常,但在Sign_in视图中我显示提供者

<%- if devise_mapping.omniauthable? %>
       <%- resource_class.omniauth_providers.each do |provider| %>          
          <%= link_to "#{OmniAuth::Utils.camelize(provider)},", omniauth_authorize_path(resource_name, provider), class: "#{provider} bold" %>  
       <% end -%>
    <% end -%>

问题是因为视图显示:

  

Facebook,微博,GoogleOauth2

GoogleOauth2看起来非常糟糕,所以如何将GoogleOauth2的名称更改为“Google”我试过这个但没有工作

<%- if devise_mapping.omniauthable? %>
   <%- resource_class.omniauth_providers.each do |provider| %>
      <% provider = "Google" if provider == "GoogleOauth2" %>          
      <%= link_to "#{OmniAuth::Utils.camelize(provider)},", omniauth_authorize_path(resource_name, provider), class: "#{provider} bold" %>  
   <% end -%>
<% end -%>

提供商:

  

设计:omniauthable,omniauth_providers:[:facebook,:twitter,:google_oauth2]

我也试过这个“google_oauth2”:

<%- if devise_mapping.omniauthable? %>
       <%- resource_class.omniauth_providers.each do |provider| %>
          <% provider = "Google" if provider == "google_oauth2" %>          
          <%= link_to "#{OmniAuth::Utils.camelize(provider)},", omniauth_authorize_path(resource_name, provider), class: "#{provider} bold" %>  
       <% end -%>
    <% end -%>

1 个答案:

答案 0 :(得分:0)

<% provider = "Google" if provider == "GoogleOauth2" %>

如果provider

,则只会修改GoogleOauth2的值

修改

根据评论,您需要的是显示文字的 “漂亮” 的另一个变量,但保留原始值为link_to助手,所以我会这样做:

<%= pretty_provider = provider == 'GoogleOauth2' ? "Google": provider %> 
<%= link_to "#{OmniAuth::Utils.camelize(pretty_provider)},", omniauth_authorize_path(resource_name, provider), class: "#{pretty_provider} bold" %>