Class: Chats::ReactionsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Chats::ReactionsController
- Defined in:
- app/controllers/chats/reactions_controller.rb
Overview
Emoji reactions: tap-to-toggle, one endpoint.
Instance Method Summary collapse
-
#create ⇒ Object
Toggle: adds or removes (Reaction.toggle! is race-safe through the unique index).
Instance Method Details
#create ⇒ Object
Toggle: adds or removes (Reaction.toggle! is race-safe through the unique index). The response re-renders the bubble for the actor; the broadcast updates everyone else.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/controllers/chats/reactions_controller.rb', line 9 def create conversation = find_conversation(params[:conversation_id]) = conversation..find(params[:message_id]) Chats::Reaction.toggle!( message: , reactor: , emoji: params.require(:emoji) ) respond_to do |format| format.turbo_stream do render turbo_stream: turbo_stream.replace( , partial: "chats/messages/message", locals: { message: } ) end format.html { redirect_to conversation_path(conversation) } end rescue ActiveRecord::RecordInvalid head :unprocessable_entity end |