This is my in my pages.home.html.erb
<div id="favorites-div"> <% if current_user.voted_for? item %> <%= link_to '<i class="fas fa-minus-square plus_and_minus_button"></i>'.html_safe, item_unlike_path(item.id)%> <% else %> <%= link_to '<i class="fas fa-plus-square plus_and_minus_button"></i>'.html_safe, item_like_path(item.id)%> <% end %> </div>
I am using a 'acts_as_votable' gem
I have nested these 2 get's in my items: routes: get 'like', to: 'items#like' get 'unlike', to: 'items#unlike'
In my items controller I have defined 2 methods: def like item = Item.find(params['item_id']) item.liked_by current_user redirect_back fallback_location: root_path end
def unlike item = Item.find(params['item_id']) item.unliked_by current_user redirect_back fallback_location: root_path end
4.1 These two methods are available in the whole ItemsController class and they are not inside inside any of the CRUD methods.
My questions would be: 1. What JS function would you recommend? Do I remove and then add the ID in the div? 2.Do I just load the div again? (.load) 3. Do i need to create a new file in my Rails app to implement this method?
Your kind help is very appreciated!