Last active
August 29, 2015 14:10
-
-
Save bayendor/2bad2a1717e623d345e8 to your computer and use it in GitHub Desktop.
Rails Session Use Examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Counter | |
def self.counter(session) | |
session[:hit_counter] ||= 0 | |
session[:hit_counter] += 1 | |
end | |
end | |
# access with | |
class ItemsController < ApplicationController | |
before_action :load_counter | |
def load_counter | |
session[:counter] ||= 0 | |
session[:counter] += 1 | |
@visits_count = session[:counter] | |
end | |
end | |
def load_cart | |
@cart = Cart.new(session[:cart] | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment