samedi 22 janvier 2022

In the destroy function of my Controller i want to delete current form id and previous n form id's

In my controller currently i'm deleting a letter from an author with id:x which is posted to the customer(state:delivered) in a database table which is an active record. I also have other states: written, posted, read. for the same author.

How do i delete all the states of the same author on pressing the delete button.

This is the old code for deleting single state:

  def destroy
    @letter = ::Adp::WritestheUpdate.find(params[:id])
    @letter.destroy
    respond_to do |format|
        format.html { redirect_to manage_adp_writes_the_updates_path, notice: 'Successfully deleted.' }
        format.json { head :no_content }
    end
  end

This is the new code i have tried for deleting multiple states

  def destroy
    @letters = author.ADP::WritestheUpdate.includes(:written, :posted, 
    :read,:deleted).find(params[:id])
    @letters.destroy
    respond_to do |format|
        format.html { redirect_to manage_adp_writes_the_updates_path, notice: 
         'Successfully deleted.' }
        format.json { head :no_content }
    end
  end

Aucun commentaire:

Enregistrer un commentaire