我该怎么做,在用户添加一些东西到购物车,并在重新打开 rails 后离开浏览器(关闭)恢复它的会话,用户可以购物更多......现在我有这样的
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :current_cart
private
def current_cart
Cart.find(session[:cart_id])
@cart = Cart.find(session[:cart_id])
rescue ActiveRecord::RecordNotFound
cart = Cart.create
session[:cart_id] = cart.id
cart
end
end
并在下订单后销毁:
def destroy
@cart = current_cart
@cart.destroy
session[:cart_id] = nil
respond_to do |format|
format.html { redirect_to session[:prev_url],
:notice => I18n.t(:empty_card) }
format.json { head :ok }
end
end
但是我怎样才能告诉 RoR 让这个会话保持活跃呢?