futzing with cookies in 15.12, although my cookie counter is getting called twice per request... perhaps the "before_filter" method is applied for each filter in a chain?

This commit is contained in:
Dan Buch 2011-08-10 22:02:04 -04:00
parent 785c1cfe20
commit feaea1636c
2 changed files with 23 additions and 14 deletions

View File

@ -1,7 +1,14 @@
class ApplicationController < ActionController::Base class ApplicationController < ActionController::Base
before_filter :set_user before_filter :set_user, :count_visits
protect_from_forgery protect_from_forgery
private
def count_visits
value = (cookies[:visits] || '0').to_i
cookies[:visits] = (value + 1).to_s
@visits = cookies[:visits]
end
protected protected
def set_user def set_user
@user = User.find(session[:id]) if @user.nil? && session[:id] @user = User.find(session[:id]) if @user.nil? && session[:id]

View File

@ -1,2 +1,4 @@
<p>You first visited this site on <%= session[:first_time] %>.</p> <p>You first visited this site on <%= session[:first_time] %>.</p>
<p>That was <%= time_ago_in_words session[:first_time] %> ago.</p> <p>That was <%= time_ago_in_words session[:first_time] %> ago.</p>
<p>You have visited this website&#39;s pages <%= @visits %> time(s).</p>