MHZ GAMER
MHZ GAMER

Reputation: 11

My Delete method is not working, after disabling "Turbo" in rails 7?

I am working on rails 7. I'm trying to run my 'Delete' method after disabling 'Turbo' but its not working, it keeps getting to my 'show.html.erb' file instead of deleting the specific data. Here is my 'Delete' action code:

<td>

    <%= link_to 'Delete', friend_path(friend),  data: { turbo:false ,confirm: 'Are you sure?'}, method: :delete, :class=>"btn btn-danger"%>

  </td>

And below is the controller method to destroy/delete data:

def destroy 
debugger
@friend = Friend.find(params[:id])
@friend.destroy

if @friend.destroy
    redirect_to friends_path, notice: "Deleted Successfully!!!"
else
  render :index, status: :unprocessable_entity

end

end

Upvotes: 0

Views: 972

Answers (1)

MZaragoza
MZaragoza

Reputation: 10111

Delete is not working is because you are not loading jQuery after disabling 'Turbo'.

Add jquery to your layout or page

<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>

and it should start working again

Upvotes: 0

Related Questions