# Session modify user updated\_at

**URL:** <https://www.ruby-forum.com/t/session-modify-user-updated-at/170544>\
**Category:** Rails\
**Created:** [June 18, 2009, 6:32pm UTC](https://www.ruby-forum.com/t/session-modify-user-updated-at/170544 "2009-06-18T18:32:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sean\_McGilvray](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8c91f0/32.png) [@Sean\_McGilvray](https://www.ruby-forum.com/u/Sean_McGilvray)\
**Post date:** [June 18, 2009, 6:32pm UTC](https://www.ruby-forum.com/t/session-modify-user-updated-at/170544/1 "2009-06-18T18:32:47Z")

</div>

I have a system that uses sessions for users to display their  
personalized site. I want to modify the updated\_at field in the  
database when ever their personal account is viewed. Any ideas?

Thank you,

Sean McGilvray

---

<div class="post-metadata">

**Author:** ![Sean\_McGilvray](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8c91f0/32.png) [@Sean\_McGilvray](https://www.ruby-forum.com/u/Sean_McGilvray)\
**Post date:** [June 18, 2009, 7:46pm UTC](https://www.ruby-forum.com/t/session-modify-user-updated-at/170544/2 "2009-06-18T19:46:42Z")

</div>

Personally I’d use a last\_visited field instead, since the record wasn’t  
actually updated.  
That said, maybe this will help for what you’re asking to do:

> **[hacking activerecord’s automatic timestamps](https://blog.evanweaver.com/2006/12/26/hacking-activerecords-automatic-timestamps/)**
>
> ActiveRecord’s automatic timestamping is handy. But what if we want some attributes to be exempt? Here’s how.why do we need this? Say we have a full-text search client that periodically updates the…

On Thu, Jun 18, 2009 at 11:32 AM, Sean McGilvray  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> I have a system that uses sessions for users to display their  
> personalized site. I want to modify the updated\_at field in the  
> database when ever their personal account is viewed. Any ideas?
> 
> Thank you,
> 
> Sean McGilvray
> 
> >

–  
Christopher W.  
removed\_email\_address@domain.invalid  
612.424.9880

---

<div class="post-metadata">

**Author:** ![Sean\_McGilvray](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8c91f0/32.png) [@Sean\_McGilvray](https://www.ruby-forum.com/u/Sean_McGilvray)\
**Post date:** [June 18, 2009, 7:56pm UTC](https://www.ruby-forum.com/t/session-modify-user-updated-at/170544/3 "2009-06-18T19:56:06Z")

</div>

How would you implement the last\_visited?

Sean McGilvray  
Executive Recruiter  
Identity Theft Specialist  
Pre-Paid Legal Service’s, Inc. NYSE:PPD  
Phone: 760-486-1019  
removed\_email\_address@domain.invalid  
[http://www.transferhome.net](http://www.transferhome.net)

On Thu, Jun 18, 2009 at 9:55 AM, Christopher W. \<

---

<div class="post-metadata">

**Author:** ![Sean\_McGilvray](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8c91f0/32.png) [@Sean\_McGilvray](https://www.ruby-forum.com/u/Sean_McGilvray)\
**Post date:** [June 18, 2009, 8:37pm UTC](https://www.ruby-forum.com/t/session-modify-user-updated-at/170544/4 "2009-06-18T20:37:10Z")

</div>

You say you’d like to track when their account was last viewed. Do you  
mean  
viewed by the user, or viewed by someone else?  
That said, if it’s by the user, update last\_visited when the user logs  
in.  
If it’s someone else, update last\_visited when the view is loaded to  
show  
that user’s information. You could run in to some trouble with that if  
you  
start doing page caching, though.

On Thu, Jun 18, 2009 at 12:54 PM, Sean McGilvray  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> >

–  
Christopher W.  
removed\_email\_address@domain.invalid  
612.424.9880

---

<div class="post-metadata">

**Author:** ![Sean\_McGilvray](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8c91f0/32.png) [@Sean\_McGilvray](https://www.ruby-forum.com/u/Sean_McGilvray)\
**Post date:** [June 19, 2009, 1:22am UTC](https://www.ruby-forum.com/t/session-modify-user-updated-at/170544/5 "2009-06-19T01:22:03Z")

</div>

On Jun 18, 6:54 pm, Sean McGilvray [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> How would you implement the last\_visited?

As Sean says, it sounds like you’re looking for a field that’s  
somewhat different to what updated\_at is supposed to represent.

To track the visit information, you could add a last\_visited datetime  
to your model. You would add the code:

@user.update\_attribute(:last\_visited, Time::now)

to the action that you wanted to record access to. You can also do the  
same with the updated\_at field if you prefer.

-Matt
