'Confirm not working with rails (version 6.11)
I am working on a application with rails 6.11 ,but confirm is not working .I have tried many option ,but still it is not working. I want to confirm before deleting a record in database. Following are related files with code: showboard.html.erb
<table class="table table-bordered">
<thead>
<tr>
<th>Name</th>
<th>Company Name</th>
<th>Status</th>
<th>Price</th>
<th>Screen Size</th>
<th>Viewership</th>
<th>Type</th>
<th>Location</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<% @board2.each do |board| %>
<tr>
<td> <%=board.name %></td>
<td> <%=board.company_name %></td>
<td> <%=board.status %></td>
<td> <%=board.price %></td>
<td> <%=board.screen_size %></td>
<td> <%=board.viewership_count %></td>
<td> <%=board.tpye %></td>
<td> <%=board.location %></td>
<td>
<%= link_to "Edit", edit_showboard_path(board.id),data: { confirm: 'Are you sure?' },class: "btn btn-primary btn-user"%>
<%= button_to "Delete", showboard_path(board.id) , method: :delete,form: { data: {confirm: "Are you sure?" } } , class: "btn btn-danger btn-user" %></td>
</tr>
<%end%>
</tbody>
showboard controller:
class ShowboardsController < ApplicationController
def showboards
@board = Board.all
@user = Owner.find_by(id: session[:user_id])
@board2 = Board.where(company_name: @user.company_name)
end
def edit
@board = Board.find(params[:id])
end
def update
@board = Board.find(params[:id])
if @board.update(board_params)
redirect_to showboards_path
else
render edit
end
end
def destroy
@board = Board.find(params[:id])
if @board.destroy
flash[:notice] ="Board deleted successfully!"
redirect_to showboards_path
end
end
private
def board_params
params.permit(:name, :company_name, :screen_size, :location, :price, :tpye, :status, :viewership_count)
end
end
application.js
import Rails from "@rails/ujs"
import Turbolinks from "turbolinks"
import * as ActiveStorage from "@rails/activestorage"
import "channels"
Rails.start()
Turbolinks.start()
ActiveStorage.start()
Looking forward to see your responses.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
