# Sessions do not update created\_at column?

**URL:** <https://www.ruby-forum.com/t/sessions-do-not-update-created-at-column/160048>\
**Category:** Rails\
**Created:** [February 11, 2009, 10:31am UTC](https://www.ruby-forum.com/t/sessions-do-not-update-created-at-column/160048 "2009-02-11T10:31:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![artchrst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e36b37/32.png) [@artchrst](https://www.ruby-forum.com/u/artchrst)\
**Post date:** [February 11, 2009, 10:31am UTC](https://www.ruby-forum.com/t/sessions-do-not-update-created-at-column/160048/1 "2009-02-11T10:31:49Z")

</div>

Hi All,

I added a column to the sessions table called “created\_at” in order to  
allow the created time to be recorded.

However, different from other Models, the column does not update  
automatically.

Therefore, what codes should I add to update the sessions.“created\_at”  
value?

It is important for avoiding hacker keeping the sessions alive.

Thanks much!  
Arthur

---

<div class="post-metadata">

**Author:** ![artchrst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e36b37/32.png) [@artchrst](https://www.ruby-forum.com/u/artchrst)\
**Post date:** [February 11, 2009, 10:36am UTC](https://www.ruby-forum.com/t/sessions-do-not-update-created-at-column/160048/2 "2009-02-11T10:36:04Z")

</div>

On Feb 11, 9:31 am, Arthur C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Hi All,
> 
> I added a column to the sessions table called “created\_at” in order to  
> allow the created time to be recorded.
> 
> However, different from other Models, the column does not update  
> automatically.

What flavour of active record store do you use ? Some people use ones  
which mostly bypass activerecord (and as a result you don’t get some  
of the stuff AR gives you for free),

Fred

---

<div class="post-metadata">

**Author:** ![artchrst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e36b37/32.png) [@artchrst](https://www.ruby-forum.com/u/artchrst)\
**Post date:** [February 11, 2009, 10:46am UTC](https://www.ruby-forum.com/t/sessions-do-not-update-created-at-column/160048/3 "2009-02-11T10:46:32Z")

</div>

Hi Fred,

Do you mean?

config.action\_controller.session\_store = :active\_record\_store

I am setting up as the above.

Does it mean that I should have the function?

Thanks  
Arthur

Frederick C. wrote:

> On Feb 11, 9:31ï¿½am, Arthur C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > Hi All,
> > 
> > I added a column to the sessions table called “created\_at” in order to  
> > allow the created time to be recorded.
> > 
> > However, different from other Models, the column does not update  
> > automatically.
> 
> What flavour of active record store do you use ? Some people use ones  
> which mostly bypass activerecord (and as a result you don’t get some  
> of the stuff AR gives you for free),
> 
> Fred

---

<div class="post-metadata">

**Author:** ![artchrst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e36b37/32.png) [@artchrst](https://www.ruby-forum.com/u/artchrst)\
**Post date:** [February 11, 2009, 11:11am UTC](https://www.ruby-forum.com/t/sessions-do-not-update-created-at-column/160048/4 "2009-02-11T11:11:55Z")

</div>

Created\_at is supposed to be filled only at creation time, right?  
Shouldn’t  
you use updated\_at instead?

On Wed, Feb 11, 2009 at 7:31 AM, Arthur C. \<

---

<div class="post-metadata">

**Author:** ![artchrst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e36b37/32.png) [@artchrst](https://www.ruby-forum.com/u/artchrst)\
**Post date:** [February 11, 2009, 11:17am UTC](https://www.ruby-forum.com/t/sessions-do-not-update-created-at-column/160048/5 "2009-02-11T11:17:37Z")

</div>

Yes.

The problem is that the field has not been filled at any time…

I just want both “created\_at” and “updated\_at” be filled in  
automatically.

Mathieu R. wrote:

> Created\_at is supposed to be filled only at creation time, right?  
> Shouldn’t  
> you use updated\_at instead?
> 
> On Wed, Feb 11, 2009 at 7:31 AM, Arthur C. \<

---

<div class="post-metadata">

**Author:** ![artchrst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e36b37/32.png) [@artchrst](https://www.ruby-forum.com/u/artchrst)\
**Post date:** [February 11, 2009, 11:22am UTC](https://www.ruby-forum.com/t/sessions-do-not-update-created-at-column/160048/6 "2009-02-11T11:22:28Z")

</div>

With default AR it always did this for me automatically… Frederick  
said  
something about using a different flavour of AR, but that’s beyond my  
knowledge…

On Wed, Feb 11, 2009 at 8:17 AM, Arthur C. \<

---

<div class="post-metadata">

**Author:** ![artchrst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e36b37/32.png) [@artchrst](https://www.ruby-forum.com/u/artchrst)\
**Post date:** [February 11, 2009, 12:58pm UTC](https://www.ruby-forum.com/t/sessions-do-not-update-created-at-column/160048/7 "2009-02-11T12:58:22Z")

</div>

On 11 Feb 2009, at 10:21, Mathieu R. wrote:

> With default AR it always did this for me automatically… Frederick  
> said something about using a different flavour of AR, but that’s  
> beyond my knowledge…

To expand on what I said, when you use active\_record\_store you provide  
a session class that handles the loading and saving of the data (as  
opposed to the other bits of a session store). Rails provides an  
implementation which is just a plain old model class but you can  
replace that with one that just issues raw sql statements (mostly in  
the interest of speed). An example one is included with rails.  
Obviously if you didn’t know any of that you probably haven;'t done  
that 🙂

In the absence of all that created\_at and updated\_at should update  
automatically as it is just a regular ActiveRecord class. Dumb  
question: did you restart your mongrel or whatever is handling your  
requests after you added that column ?

Fred
