ruby on rails - Implementing a timer like that of Stackoverflow -


stackoverflow prevents 1 posting many comments in short period of time, granting him 15 seconds delay after posting each comment. in rails application, want implement different feature uses same logic. if user reading post more 5 minutes, want add him post's readers table. done using sessions or cookies?

update: think more, logic maybe different. after 5 minutes, need check 1 more time if user still on page, reading post.

clarification: want implement method check whether user has been reading same post longer 5 minutes.

there many questions asking, without knowing workflow of app difficult answer question. break down easier others also.

now, answer part of question, can timing session. maybe?

def methodname   if session[:logged_in]     do_something if session[:last_seen] < 5.minutes.from_now     session[:last_seen] = time.now   else     do_something_else     session[:last_seen] = time.now   end end 

hope helps. let me know if have questions.


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

php - HTTP_REFERER woes: How can I allow access to a specific page, only when a visitor has visited another specific page beforehand? -