Advertisement
Guest User

Untitled

a guest
Apr 13th, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 0.76 KB | None | 0 0
  1. Twoots controller:
  2.  
  3.   def comment_like
  4.     @twoot = Twoot.find(params[:id])
  5.     @comment = NO IDEA WHAT TO PUT THERE
  6.     current_user.favorite(@comment)
  7.     redirect_to twoot_path(@twoot)
  8.   end
  9.  
  10.   def comment_unlike
  11.     @twoot = Twoot.find(params[:id])
  12.     @comment = SAME, NO IDEA
  13.     current_user.remove_favorite(@comment)
  14.     redirect_to twoot_path(@twoot)
  15.   end
  16.  
  17.  
  18. Views:
  19. <% @comments.each do |comment| %>
  20. ...
  21. <% if user_signed_in? %>
  22.   <% if comment.favorited_by?(current_user) %>
  23.     <%= button_to 'Unlike', {action: "comment_unlike" }, { class: "btn waves-effect hoverable red lighten-2" } %>
  24.    <% else %>
  25.     <%= button_to 'Like', {action: "comment_like" }, { class: "btn waves-effect hoverable red lighten-2" } %>
  26. <% end %>
  27. <% end %>
  28. <% end %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement