Advertisement
Guest User

Untitled

a guest
Aug 27th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. <!-- Like/Unlike Button -->
  2. <% if current_user %>
  3. <!-- If the user is signed in, allow them to vote -->
  4. <div class="votes">
  5. <% if (current_user.liked? resource) %>
  6. <!-- Unlike -->
  7. <%= render(:partial => 'unlike', :locals => {:resource => resource})%>
  8. <% else %>
  9. <!-- Like -->
  10. <%= render(:partial => 'like', :locals => {:resource => resource})%>
  11. <% end %>
  12. </div>
  13. <% else %>
  14.  
  15. <!-- If the user is not signed in, send them to Twitter -->
  16. <%= link_to "/auth/twitter" do %>
  17. <button class="ui basic compact icon right floated button" data-tooltip="You need to sign in before saving this link." data-variation="basic" data-position="top right">
  18. <i class="heart icon" style="color: #EDB0B1"></i> <%= resource.get_likes.size %>
  19. </button>
  20. <% end %>
  21. <% end %>
  22.  
  23. <%= link_to like_resource_path(resource), method: :get, remote: true, class: 'like_resource' do %>
  24. <button class="ui basic compact icon right floated button vote_count">
  25. <i class="heart icon" style="color: #F1F1F1"></i> <%= resource.get_likes.size %>
  26. </button>
  27.  
  28. get 'auth/twitter/callback', to: 'sessions#create'
  29.  
  30. class SessionsController < ApplicationController
  31. def create
  32. auth = request.env["omniauth.auth"]
  33. user = User.from_omniauth(auth)
  34. session[:user_id] = user.id
  35. redirect_to user, :notice => "Signed in!"
  36. end
  37.  
  38. def destroy
  39. session[:user_id] = nil
  40. redirect_to root_url, :notice => "Signed out!"
  41. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement