Why isnt my simple counter working?

You’ve set the @count variable in the index method. Is it set in your add_to_cart method as well? Perhaps you could extract that into a before_filter to set @count for you. Something like this may get you started

before_fitler :set_visits

def index

increment_count

set_visits

end

private

def increment_count

session[:counter] ||= 0

session[:counter] += 1

end

def set_visits

@count = session[:counter]

end