Low commit activity in last 3 years
No release in over a year
Quick concern for session variables
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

SessionRememberable

Quick gem for remembering and forgetting data in a session.

Installation

Add this line to your application's Gemfile:

gem 'session_rememberable'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install session_rememberable

Usage

Incluce SessionRememberable concern in your application controller and define some keys to remember.

class ApplicationController < ActionController::Base
  include SessionRememberable

  remember :cart
  remember :customer, class_name: 'User'
  remember :visits, static_data: true
end

In your controllers

class CustomersController < ApplicationController

  def create
    customer = User.new(permitted_params)

    if customer.save
      remember customer
      redirect_to customer
    else
      render :new
    end
  end

  def destroy
    customer = User.find(params[:id])

    if customer.destroy
      forget customer
      redirect_to root_path
    else
      render :edit
    end
  end

  private

    def permitted_params
      params.require(:customer).permit(:name, :email)
    end
end

In your views (.html.haml)

%h1
  Welcome
  = current_customer.name

Initializer

config/initializers/session_store.rb

Rails.application.config.session_store SessionRememberable::Store, {
  rememberable_options: {
    permanent: true
  }
}