Skip to content

Rails 7: link_to delete not working (wrong redirect) #44170

@collimarco

Description

@collimarco

Steps to reproduce

View:

<%= link_to "Destroy", @question, data: { 'turbo-method': :delete, 'turbo-confirm': 'Are you sure?' } %>

Controller:

  def destroy
    @question = current_user.questions.find(params[:id])
    @question.destroy
    redirect_to questions_url, notice: "Question was successfully destroyed."
  end

Expected behavior

The question is deleted and the user redirected to the questions index.

Actual behavior

The question is deleted and the user is redirected to the question (instead of question index as defined in the controller!) where he gets an obvious error:

ActiveRecord::RecordNotFound in QuestionsController#show
Couldn't find Question with 'id'=6
inside def show

System configuration

Rails version: 7.0.1

Ruby version: 3.1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions