if a User has many articles and these articles belong to a user. Then with a regular scaffold you want to set a time limit until it can no longer be deleted anymore:
def destroy
@article = Article.find(params[:id])
@article.destroy
respond_to do |format|
format.html { redirect_to articles_url }
format.json { head :ok }
format.js
end
end
How would you permanently disable the delete functionality for the User’s articles?
First of all, you should hide this logic in the model and you should make it available as a public method:
Then in your views you can do things like this:
You’ll also want a
before_destroycallback in the model that returnsfalseto stop invalid destroys:You could also add an explicit
@model.destroyable?check to yourdestroycontroller depending on how you want to handle errors.