I am trying to make an app in Rails 4.
I am trying to set up devise with omniauth and each of Facebook, linkedin, twitter and googleauth. Im currently trying to follow this tutorial.
http://sourcey.com/rails-4-omniauth-using-devise-with-twitter-facebook-and-linkedin/
I have models called:
user.rb, profile.rb and identity.rb
The associations are:
User
has_one :profile, dependent: :destroy
has_many :identities, dependent: :destroy
Profile
belongs_to :user
Identity
belongs_to :user
Identity also validates:
validates_presence_of :uid, :provider
validates_uniqueness_of :uid, :scope => :provider
I am trying to make a partial in my user views folder that lists out each of the optional authentication methods and shows whether a user has used them to connect or if not, providing a link to connect them.
I have made:
<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>
I want to show this partial in the profile edit form.
<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>
I can't figure out how to write the chain so that when a user updates their profile, they can connect other social media accounts to their identity.
Can anyone see where I've gone wrong?
I've tried a few different things to get these chains linked including:
<% if @profile.user.identity.provider == 'facebook' %>
<% if @current_user.profile.identity.provider == 'facebook' %>
<% if @user.profile.identity.provider == 'facebook' %>
Im just guessing with this - I can't figure it out. Can anyone see what I've done wrong?