Skip to content

Instantly share code, notes, and snippets.

@phirefly
Created May 27, 2020 00:12
Show Gist options
  • Save phirefly/017e00469468f6f6275a4c8013a2b480 to your computer and use it in GitHub Desktop.
Save phirefly/017e00469468f6f6275a4c8013a2b480 to your computer and use it in GitHub Desktop.
FavoriteReflex code
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