# Deleting Data After Viewing On Page

**URL:** <https://www.ruby-forum.com/t/deleting-data-after-viewing-on-page/174388>\
**Category:** Rails\
**Created:** [August 26, 2009, 7:38am UTC](https://www.ruby-forum.com/t/deleting-data-after-viewing-on-page/174388 "2009-08-26T07:38:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tdellaringa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7bcc69/32.png) [@tdellaringa](https://www.ruby-forum.com/u/tdellaringa)\
**Post date:** [August 26, 2009, 7:38am UTC](https://www.ruby-forum.com/t/deleting-data-after-viewing-on-page/174388/1 "2009-08-26T07:38:04Z")

</div>

I’m creating a site that allows users to upload a picture. The picture  
they uploaded will be shown randomly for a period of time then another  
one will come on. When they upload it, they pay a certain price,  
depending on how many times they want it to be viewed. I want it to be  
made that it’s one dollar per amount of times it can be viewed. Thus,  
if they pay $5, their picture will be shown 5 random times, but no more.  
My question is how to do this. I want to figure out how to make the data  
in the table delete itself after it is viewed the amount of times paid  
for. I’m not sure how to count the number of views nor make the data  
delete itself. Any help would be greatly appreciated!

---

<div class="post-metadata">

**Author:** ![tdellaringa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7bcc69/32.png) [@tdellaringa](https://www.ruby-forum.com/u/tdellaringa)\
**Post date:** [August 26, 2009, 7:52am UTC](https://www.ruby-forum.com/t/deleting-data-after-viewing-on-page/174388/2 "2009-08-26T07:52:49Z")

</div>

Tom D. wrote:

> I’m creating a site that allows users to upload a picture. The picture  
> they uploaded will be shown randomly for a period of time then another  
> one will come on. When they upload it, they pay a certain price,  
> depending on how many times they want it to be viewed. I want it to be  
> made that it’s one dollar per amount of times it can be viewed. Thus,  
> if they pay $5, their picture will be shown 5 random times, but no more.  
> My question is how to do this. I want to figure out how to make the data  
> in the table delete itself after it is viewed the amount of times paid  
> for. I’m not sure how to count the number of views nor make the data  
> delete itself. Any help would be greatly appreciated!

you can do something like this  
add column “picture\_view” in database put value of it is equal to amount  
that user pay if user pay $5 then make picture\_view=5  
then after each time picture shown reduce picture\_views count by 1  
if picture\_view is 0(zero) then give such a condition that it will not  
be displayed

---

<div class="post-metadata">

**Author:** ![tdellaringa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7bcc69/32.png) [@tdellaringa](https://www.ruby-forum.com/u/tdellaringa)\
**Post date:** [August 26, 2009, 10:09am UTC](https://www.ruby-forum.com/t/deleting-data-after-viewing-on-page/174388/3 "2009-08-26T10:09:35Z")

</div>

My understand is before displaying a picture, you should check the  
user’s  
account, if there’s no enough money then redirect to some page to show a  
notice.  
Since users and pictures are n:n relationships, if you want to add a  
column to record times each people view the picture, it would be  
amount\_of\_users \* amount\_of\_pics records needed. And I don’t think you  
need  
to delete the picture.

before\_filter :check\_account, :only =\> :display\_pic

def display\_pic

# random get pic

end

private  
def check\_account  
redirect\_to :some\_where if current\_user.balance \< price\_per\_pic  
end
