Skip to content

Instantly share code, notes, and snippets.

@bayendor
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bayendor/2bad2a1717e623d345e8 to your computer and use it in GitHub Desktop.
Save bayendor/2bad2a1717e623d345e8 to your computer and use it in GitHub Desktop.
Rails Session Use Examples
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