I have a simple model in RoR and I would like to keep eveything people enter on the site. But I also want to be able to hide some content if the user click on “Remove”.
So I added a bolean attribute in my model called “displayed”.
I would like to know, what would be the best-practices-styled method.
I guess I have to change the controller with something like :
def destroy
@point = Point.find(params[:id])
@point.displayed = false
@point.save
respond_to do |format|
format.html { redirect_to points_url }
format.json { head :no_content }
end
But I am not sure it is clean. What would be the best way to do it.
As you guess I am noobish with RoR. Chunks of code would be appreciated.
Thank you
Something like this:
And then call
@point.archivein the destroy action of your controller where you would normally call@point.destroy. You can also create adefault_scopeto hide archived points until you explicitly query for them, seethe RoR guide on appling a default scope.Edit: Updated my answer as per normalocity & logan’s comments below.