# Automatically decrement value each day

**URL:** <https://www.ruby-forum.com/t/automatically-decrement-value-each-day/189379>\
**Category:** Rails\
**Created:** [May 30, 2010, 6:36pm UTC](https://www.ruby-forum.com/t/automatically-decrement-value-each-day/189379 "2010-05-30T18:36:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![beckyrussoniello](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/76d3ee/32.png) [@beckyrussoniello](https://www.ruby-forum.com/u/beckyrussoniello)\
**Post date:** [May 30, 2010, 6:36pm UTC](https://www.ruby-forum.com/t/automatically-decrement-value-each-day/189379/1 "2010-05-30T18:36:47Z")

</div>

I have a Person model with a points attribute. For the most part,  
points values will be incremented and decremented via user votes.  
However, I’d also like to decrement a Person’s points by half a point  
each day.

How do I automatically decrement the value once per day?

Your help is greatly appreciated 🙂

Becky

---

<div class="post-metadata">

**Author:** ![beckyrussoniello](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/76d3ee/32.png) [@beckyrussoniello](https://www.ruby-forum.com/u/beckyrussoniello)\
**Post date:** [May 30, 2010, 7:34pm UTC](https://www.ruby-forum.com/t/automatically-decrement-value-each-day/189379/2 "2010-05-30T19:34:34Z")

</div>

Id suggest using a database job but you could always just store when you  
last decreased it date and then on sign in do the decrease. If you plan  
on  
showing other users the points you’d need the job.

On May 30, 2010 12:37 PM, “Becky Russoniello” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

I have a Person model with a points attribute. For the most part,  
points values will be incremented and decremented via user votes.  
However, I’d also like to decrement a Person’s points by half a point  
each day.

How do I automatically decrement the value once per day?

Your help is greatly appreciated 🙂

## Becky

Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

–  
You received this message because you are subscribed to the Google  
Groups  
“Ruby on Rails: Talk” group.  
To post to this group, send email to removed\_email\_address@domain.invalid.  
To unsubscribe from this group, send email to  
removed\_email\_address@domain.invalid[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
.  
For more options, visit this group at  
[http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en).

---

<div class="post-metadata">

**Author:** ![beckyrussoniello](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/76d3ee/32.png) [@beckyrussoniello](https://www.ruby-forum.com/u/beckyrussoniello)\
**Post date:** [May 30, 2010, 8:35pm UTC](https://www.ruby-forum.com/t/automatically-decrement-value-each-day/189379/3 "2010-05-30T20:35:16Z")

</div>

Hi Tim,

Thanks for responding. Sorry if this is a dumb question, but what do  
you mean by database job?

This is going to be a ranked list (current points value determines the  
ranking), and I’d like users to be able to view the list without being  
logged in.

Tim L. wrote:

> Id suggest using a database job but you could always just store when you  
> last decreased it date and then on sign in do the decrease. If you plan  
> on  
> showing other users the points you’d need the job.

---

<div class="post-metadata">

**Author:** ![beckyrussoniello](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/76d3ee/32.png) [@beckyrussoniello](https://www.ruby-forum.com/u/beckyrussoniello)\
**Post date:** [May 30, 2010, 11:05pm UTC](https://www.ruby-forum.com/t/automatically-decrement-value-each-day/189379/4 "2010-05-30T23:05:50Z")

</div>

I would use a scheduler for this kind of stuff. A pure ruby solution  
is rufus scheduler:

> **[GitHub - jmettraux/rufus-scheduler: scheduler for Ruby (at, in, cron and...](https://github.com/jmettraux/rufus-scheduler)**
>
> scheduler for Ruby (at, in, cron and every jobs). Contribute to jmettraux/rufus-scheduler development by creating an account on GitHub.

With rufus scheduler you can schedule a routine that runs every day at  
a given hour and decrements every persons points by 0.5.

---

<div class="post-metadata">

**Author:** ![beckyrussoniello](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/76d3ee/32.png) [@beckyrussoniello](https://www.ruby-forum.com/u/beckyrussoniello)\
**Post date:** [May 31, 2010, 8:00pm UTC](https://www.ruby-forum.com/t/automatically-decrement-value-each-day/189379/5 "2010-05-31T20:00:11Z")

</div>

no scheduler solution:

why not use created\_at or updated\_at?  
simply get current date than compute days since your prefered event and  
make  
it half…

---

<div class="post-metadata">

**Author:** ![beckyrussoniello](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/76d3ee/32.png) [@beckyrussoniello](https://www.ruby-forum.com/u/beckyrussoniello)\
**Post date:** [May 30, 2010, 11:26pm UTC](https://www.ruby-forum.com/t/automatically-decrement-value-each-day/189379/6 "2010-05-30T23:26:18Z")

</div>

Wow! Perfect. Thank you so much.

Sharagoz wrote:

> I would use a scheduler for this kind of stuff. A pure ruby solution  
> is rufus scheduler:  
> [GitHub - jmettraux/rufus-scheduler: scheduler for Ruby (at, in, cron and every jobs)](http://github.com/jmettraux/rufus-scheduler)  
> With rufus scheduler you can schedule a routine that runs every day at  
> a given hour and decrements every persons points by 0.5.
