Skip to content

Commit

Permalink
edit messages
Browse files Browse the repository at this point in the history
  • Loading branch information
yshmarov committed Nov 11, 2021
1 parent b03bb33 commit f38797b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
17 changes: 17 additions & 0 deletions app/controllers/messages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ def new

# GET /messages/1/edit
def edit
respond_to do |format|
format.turbo_stream do
render turbo_stream: turbo_stream.update(@message,
partial: "messages/form",
locals: {message: @message})
end
end
end

# POST /messages or /messages.json
Expand Down Expand Up @@ -58,9 +65,19 @@ def create
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})
end
format.html { redirect_to @message, notice: "Message was successfully updated." }
format.json { render :show, status: :ok, location: @message }
else
format.turbo_stream do
render turbo_stream: turbo_stream.update(@message,
partial: "messages/form",
locals: {message: @message})
end
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @message.errors, status: :unprocessable_entity }
end
Expand Down
1 change: 1 addition & 0 deletions app/views/messages/_message.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

<p>
<%= link_to "Show this message", message %>
<%= button_to "Edit this message", edit_message_path(message), method: :post %>
<%= button_to "Destroy this message", message_path(message), method: :delete %>
</p>
</div>
10 changes: 0 additions & 10 deletions app/views/messages/show.html.erb

This file was deleted.

6 changes: 5 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
Rails.application.routes.draw do
root "messages#index"
resources :messages
resources :messages do
member do
post :edit
end
end
end

0 comments on commit f38797b

Please sign in to comment.