Created
May 27, 2020 00:12
-
-
Save phirefly/017e00469468f6f6275a4c8013a2b480 to your computer and use it in GitHub Desktop.
FavoriteReflex code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FavoriteReflex < StimulusReflex::Reflex | |
def add_favorite | |
Favorite.create!(user_id: element.dataset[:userid], | |
thing_id: element.dataset[:thingid] | |
) | |
end | |
def remove_favorite | |
favorite = Favorite.find_by(user_id: element.dataset[:userid], | |
thing_id: element.dataset[:thingid]) | |
favorite.destroy! | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment