Forum: Ruby on Rails managing visits

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.
997433f165140d58f52b8c0d1d005dc1?d=identicon&s=25 Patrick Aljord (Guest)
on 2006-12-26 17:37
(Received via mailing list)
Hey all,
I have Users and Products, I would like to log every time a user visit
a product page.
I have:
users(id, name)
products(id,name)
what's the best way to do this? is it:
visits(id,user_id,product_id,visited_on)
with user has_many :visits
and visit belongs_to :user
and product has_many :visits
or

visits(user_id,product_id,visited_on)
with user has_many :visits through products
but I'm not sure how to manage that one

any idea?

thanx in advance

Pat
6d3c187a8b3ef53b08e3e7e8572c4fea?d=identicon&s=25 Jeremy McAnally (Guest)
on 2006-12-26 17:41
(Received via mailing list)
You could use a before_filter or after_filter on the product page
actions to create a new AR object and save it to the DB.

--Jeremy
997433f165140d58f52b8c0d1d005dc1?d=identicon&s=25 Patrick Aljord (Guest)
on 2006-12-26 17:59
(Received via mailing list)
On 12/26/06, Jeremy McAnally <jeremymcanally@gmail.com> wrote:
>
> You could use a before_filter or after_filter on the product page
> actions to create a new AR object and save it to the DB.
>
> --Jeremy
>
thanx Jeremy but I wanted to know DBwise how to manage visits.
F15fdc7cb2e911b3808837f2be244add?d=identicon&s=25 unknown (Guest)
on 2006-12-27 00:16
(Received via mailing list)
sounds like you need a products_users HABTM table with a visits field
that
you can update on each visit.  As jeremy stated, you could handle this
in a
before_filter or in the actual action for the show product page.
This topic is locked and can not be replied to.