Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 带有Desive&;Omniauth-多个社交媒体登录提供商_Ruby On Rails_Devise_Associations_Omniauth - Fatal编程技术网

Ruby on rails 带有Desive&;Omniauth-多个社交媒体登录提供商

Ruby on rails 带有Desive&;Omniauth-多个社交媒体登录提供商,ruby-on-rails,devise,associations,omniauth,Ruby On Rails,Devise,Associations,Omniauth,我正在尝试在Rails 4中制作一个应用程序 我正试图与omniauth以及Facebook、linkedin、twitter和googleauth建立Desive。我目前正在努力学习本教程 我有一些模型叫做: user.rb、profile.rb和identity.rb 这些协会是: 使用者 侧面图 belongs_to :user 身份 belongs_to :user 标识还验证: validates_presence_of :uid, :provider validates_uni

我正在尝试在Rails 4中制作一个应用程序

我正试图与omniauth以及Facebook、linkedin、twitter和googleauth建立Desive。我目前正在努力学习本教程

我有一些模型叫做:

user.rb、profile.rb和identity.rb

这些协会是:

使用者

侧面图

belongs_to :user
身份

belongs_to :user
标识还验证:

validates_presence_of :uid, :provider
validates_uniqueness_of :uid, :scope => :provider
我试图在“我的用户视图”文件夹中创建一个部分,列出每个可选的身份验证方法,并显示用户是否使用了这些方法进行连接,如果没有,则提供一个链接来连接它们

我已提出:

<table class="table table-bordered">

                    <tr>
                      <td><i class="fa fa-facebook"></i></td>   
                      <td>
                        <% if @profile.user.identity.provider == 'facebook' %>
                            <span class="glyphicon glyphicon-ok"</span>
                        <% else %>  
                            <%= link_to icon('Connect Facebook', id: 'facebookauth'), user_omniauth_authorize_path(:facebook) %>
                        <% end %>   

                      </td>
                    </tr>

                    <tr>
                      <td><i class="fa fa-google"></i></td> 
                      <td>
                        <% if @user.identity.provider includes 'googleauth' %>
                            <span class="glyphicon glyphicon-ok"</span>
                        <% else %>  
                            <%= link_to icon('Connect Google', id: 'googleauth'), user_omniauth_authorize_path(:google_oauth2) %>
                        <% end %>   

                      </td>
                    </tr>

                    <tr>
                      <td><i class="fa fa-linkedin"></i></td>   
                      <td>
                        <% if @user.identity.provider includes 'linkedin' %>
                            <span class="glyphicon glyphicon-ok"</span>
                        <% else %>  
                            <%= link_to icon('Connect Linkedin', id: 'linkedinauth'), user_omniauth_authorize_path(:linkedin) %>
                        <% end %>

                      </td>
                    </tr>


                    <tr>
                      <td><i class="fa fa-twitter"></i></td>    
                      <td>
                        <% if @user.identity.provider includes 'twitter' %>
                            <span class="glyphicon glyphicon-ok"</span>
                        <% else %>  
                            <%= link_to icon('Connect Twitter', id: 'twitterauth'), user_omniauth_authorize_path(:twitter) %>
                        <% end %>

                      </td>
                    </tr>
                </table>


User.identity不起作用,因为User
有许多
标识


您可以执行类似于
@user.identifications.map(&:provider.include?('facebook')
user.identity的操作,因为user
有许多
身份


你可以做一些类似于
@user.identifications.map(&:provider.include?('facebook')

好吧,对不起,如果我没有在这里给出太多解释,但希望你能在这里找到答案:嗨,查理。谢谢你。我花了大约3年的时间才弄明白这一点。在我放弃这种方法并尝试其他方法之前,我将再次尝试这种方法,但我已经阅读了您的博客,感谢您的分享。如果我抛开我迄今为止尝试过的一切,重新开始(这大概是我第30次尝试到这一点),那就在我的书签里了。好吧,对不起,如果我没有在这里给出太多解释,但希望你能在这里找到答案:嗨,查理。谢谢你。我花了大约3年的时间才弄明白这一点。在我放弃这种方法并尝试其他方法之前,我将再次尝试这种方法,但我已经阅读了您的博客,感谢您的分享。如果我抛开迄今为止尝试过的一切,重新开始(这大概是我第30次尝试到这一点)嗨,我最初尝试过,但忘记了问号,也不知道地图。谢谢你。我尝试此操作时出错:。错误显示:语法错误,意外的tIDENTIFIER,应为''。我知道错误消息意味着缺少一个“'),但我看不出应该在哪里添加一个。我觉得很对。@user2860931我很糟糕,我已经更新了我的答案。它应该是
&:provider
而不是
:&provider
谢谢。该错误已停止出现。现在我得到了另一个:ActiveRecord::RecordNotFound in UsersController#show找不到“id”=身份验证的用户。你能看到可能是什么原因吗?@user2860931看起来像是在传递字符串“authentications”作为params[:id]的值。如果您创建一个新问题并添加控制器代码,那就更好了。您好,我最初尝试过这个,但忘记了问号,不知道地图。谢谢你。我尝试此操作时出错:。错误显示:语法错误,意外的tIDENTIFIER,应为''。我知道错误消息意味着缺少一个“'),但我看不出应该在哪里添加一个。我觉得很对。@user2860931我很糟糕,我已经更新了我的答案。它应该是
&:provider
而不是
:&provider
谢谢。该错误已停止出现。现在我得到了另一个:ActiveRecord::RecordNotFound in UsersController#show找不到“id”=身份验证的用户。你能看到可能是什么原因吗?@user2860931看起来像是在传递字符串“authentications”作为params[:id]的值。最好创建一个新问题并添加控制器代码。
<table class="table table-bordered">

                    <tr>
                      <td><i class="fa fa-facebook"></i></td>   
                      <td>
                        <% if @profile.user.identity.provider == 'facebook' %>
                            <span class="glyphicon glyphicon-ok"</span>
                        <% else %>  
                            <%= link_to icon('Connect Facebook', id: 'facebookauth'), user_omniauth_authorize_path(:facebook) %>
                        <% end %>   

                      </td>
                    </tr>

                    <tr>
                      <td><i class="fa fa-google"></i></td> 
                      <td>
                        <% if @user.identity.provider includes 'googleauth' %>
                            <span class="glyphicon glyphicon-ok"</span>
                        <% else %>  
                            <%= link_to icon('Connect Google', id: 'googleauth'), user_omniauth_authorize_path(:google_oauth2) %>
                        <% end %>   

                      </td>
                    </tr>

                    <tr>
                      <td><i class="fa fa-linkedin"></i></td>   
                      <td>
                        <% if @user.identity.provider includes 'linkedin' %>
                            <span class="glyphicon glyphicon-ok"</span>
                        <% else %>  
                            <%= link_to icon('Connect Linkedin', id: 'linkedinauth'), user_omniauth_authorize_path(:linkedin) %>
                        <% end %>

                      </td>
                    </tr>


                    <tr>
                      <td><i class="fa fa-twitter"></i></td>    
                      <td>
                        <% if @user.identity.provider includes 'twitter' %>
                            <span class="glyphicon glyphicon-ok"</span>
                        <% else %>  
                            <%= link_to icon('Connect Twitter', id: 'twitterauth'), user_omniauth_authorize_path(:twitter) %>
                        <% end %>

                      </td>
                    </tr>
                </table>
<div class="formheader">Update your profile</div>

      <div class="row">
        <div class="col-md-10 col-md-offset-1">
            <%= render 'form' %>
            <%= render 'users/authentication' %>

        </div>
      </div>    
<% if @profile.user.identity.provider == 'facebook' %>
<% if @current_user.profile.identity.provider == 'facebook' %>
<% if @user.profile.identity.provider == 'facebook' %>