1
我正在学习实用的书架课。我尝试制作一个会话计数器。 我的存储控制器是Ruby on Rails session [:counter]增加两个
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
@cart = current_cart
@time = Time.now
@shown_message = "You've been here #{@count} times" if increment_counter >5
end
end
和我的看法是
<h5><p><%= @shown_message %></p></h5>..
,直到5倍这是行不通的。但是在它开始算作5,7,9,11之后。 。我的会话[:counter]有什么问题?
谢谢Murifox ..This解决我的问题。 – ytsejam