Hello i used this code :

class StoreController < ApplicationController def increment_counter if session[:counter].nil? session[:counter] = 0 end session[:counter] += 1 end def index @count = increment_counter @products = Product.all @time = Time.now @shown_message = “You’ve been here #{@count} times” if increment_counter >5 end end

and in the index.html.erb

<%= @shown_message %>

but it does not give the correct number. The sessions are increasing by two . like 5 times , 7 times , 9 times . can you help me?