sql - Rails - Proper associations/data model for content display "cooldown" -


i have user model , content model. when user views piece of content, need make sure user not see content again say, 48 hours.

what's rails way model out? i'd have table user_id, content_id, , timestamp view recorded, have worker clear out entries timestamps > 2 days. way when user requests more content, can filter out content has entry user_id , content_id match.

don't think should matter, i'm using mysql rails 3.2.

i think can following in model.

class user < activerecord::base    ...    has_many :contents, -> {  where(["extract(hour last_viewed_at) > ? or last_viewed_at ?", 48, nil)} end 

i used or condition make nil because when initialized or new record created user can able see it.

i not sure how using worker.

please suggest me if missing anything. not intended answer accurately, rather trying way can realize possible.


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -