Forum: Ruby on Rails override automatic update of updated_on column

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
4d0f33adeb53885ca7318bbe7bf9b1f2?d=identicon&s=25 elisfanclub (Guest)
on 2006-05-29 08:45
(Received via mailing list)
i know that title sounds confusing, but here is the deal:

the two columns that we are concerned with for this question are the
"updated_on" column and the "views" column.  the views column increases
everytime a user visits a certain page.  like this:

@object.update_attributes(:views => @object.views + 1)

the problem is that when a user visits the page, it AUTOMATICALLY
updates the "update_on" column with the current time.  i don't want this
to happen.  how can i rewrite this so it DOES NOT update the "update_on"
column and only the "views" column?

thanks

eli
731b847cae8ede704eea6f991b461072?d=identicon&s=25 Steven Talcott Smith (Guest)
on 2006-05-29 22:32
elisfanclub wrote:
> the problem is that when a user visits the page, it AUTOMATICALLY
> updates the "update_on" column with the current time.  i don't want this
> to happen.  how can i rewrite this so it DOES NOT update the "update_on"
> column and only the "views" column?

You could explicitly update the updated_on field with itself (old
value).  This will override the timestamp behavior.  I have done this
before in MySQL.  YMMV.   The resulting SQL should come out with
"updated_on = updated_on" or "updated_on = '<old value>'"


Steven
This topic is locked and can not be replied to.