Skip to content

Commit

Permalink
basic flash
Browse files Browse the repository at this point in the history
  • Loading branch information
yshmarov committed Nov 11, 2021
1 parent 9468767 commit f103be9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
15 changes: 10 additions & 5 deletions app/controllers/messages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def create
turbo_stream.prepend('messages',
partial: "messages/message",
locals: {message: @message}),
turbo_stream.update('message_counter', Message.count)
turbo_stream.update('message_counter', Message.count),
turbo_stream.update('notice', "Message #{@message.id} created")
# turbo_stream.update('message_counter', html: Message.count)
# turbo_stream.update('message_counter', html: "#{Message.count}")
# turbo_stream.append('messages',
Expand Down Expand Up @@ -69,9 +70,12 @@ def update
respond_to do |format|
if @message.update(message_params)
format.turbo_stream do
render turbo_stream: turbo_stream.update(@message,
partial: "messages/message",
locals: {message: @message})
render turbo_stream: [
turbo_stream.update(@message,
partial: "messages/message",
locals: {message: @message}),
turbo_stream.update('notice', "Message #{@message.id} updated")
]
end
format.html { redirect_to @message, notice: "Message was successfully updated." }
format.json { render :show, status: :ok, location: @message }
Expand All @@ -94,7 +98,8 @@ def destroy
format.turbo_stream do
render turbo_stream: [
turbo_stream.remove(@message),
turbo_stream.update('message_counter', Message.count)
turbo_stream.update('message_counter', Message.count),
turbo_stream.update('notice', "Message #{@message.id} deleted")
]
end
# format.turbo_stream { render turbo_stream: turbo_stream.remove("message_#{@message.id}") }
Expand Down
4 changes: 3 additions & 1 deletion app/views/messages/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<p id="notice"><%= notice %></p>
<p id="notice">
<%= notice %>
</p>

<h1>
Messages
Expand Down

0 comments on commit f103be9

Please sign in to comment.