# How to: Prevent deletes and report

**URL:** <https://www.ruby-forum.com/t/how-to-prevent-deletes-and-report/160575>\
**Category:** Rails\
**Created:** [February 17, 2009, 10:23pm UTC](https://www.ruby-forum.com/t/how-to-prevent-deletes-and-report/160575 "2009-02-17T22:23:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [February 17, 2009, 10:23pm UTC](https://www.ruby-forum.com/t/how-to-prevent-deletes-and-report/160575/1 "2009-02-17T22:23:12Z")

</div>

I have a model that may not have its entries deleted. I wish to have  
all attempts to delete records raise a notification / error, report this  
to the user, and return to the original page.

In my model file I put this:

def destroy  
errors.add\_to\_base(“Deletion prohibited!”)  
end

In the controller I have this:

# DELETE /entities/1

# DELETE /entities/1.xml

def destroy  
@entity = Entity.find(params[:id])

```
respond_to do |format|
  if @entity.destroy
    flash[:notice] = 'Entity was destroyed.'
    format.html { redirect_to(entities_url) }
    format.xml { head :ok }
  else
    format.html { redirect_to(entities_url) }
    format.xml { render :xml => @entity.errors,
                         :status => :unprocessable_entity }
  end
end

```

end

This seems to work insofar as the records are not deleted. But the  
error message is not displayed. What am I missing?

I know, just get rid of the delete link in the view. Eventually, yes,  
right now I want to assure myself that no matter how the request comes  
in the action is disallowed and an error is raised. I will probable  
want to log the attempt as well.
