mardi 25 juillet 2023

how to delete a record and go to delete page in rails 7 after installing ujs?

I am using Rails 7 and also install ujs but whenever i click on delete button Get request call rather than destroy request and i go to view record page rather then delete employee page. This is the code of delete link:

<%= link_to "Delete", employee_path(employee), method: :delete, class: "btn btn-danger", data: { confirm: "Are You sure to delete this employee" } %>

and this is the code of delete action from controller file:

def destroy
    @employee = Employee.find(params[:id])
    if @employee.destroy
      redirect_to employees_path, notice: "Employee has been deleted"
    end
  end

Aucun commentaire:

Enregistrer un commentaire