Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update does not work as expected #2

Open
overdrivemachines opened this issue Jan 9, 2023 · 0 comments
Open

Update does not work as expected #2

overdrivemachines opened this issue Jan 9, 2023 · 0 comments

Comments

@overdrivemachines
Copy link

When you update a todo, it wants to redirect to the show page. This is not what we want. We want it to render the updated todo. This is what will fix it:

def update
    respond_to do |format|
      if @todo.update(todo_params)
        format.turbo_stream do
          render turbo_stream: turbo_stream.replace("#{helpers.dom_id(@todo)}_item", partial: "todo",
                                                                                     locals: { todo: @todo })
        end
        format.html { redirect_to todo_url(@todo), notice: "Todo was successfully updated." }
      else
        format.turbo_stream do
          render turbo_stream: turbo_stream.replace("#{helpers.dom_id(@todo)}_form", partial: "form",
                                                                                     locals: { todo: @todo })
        end
        format.html { render :edit, status: :unprocessable_entity }
      end
    end
  end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant