0.0
No commit activity in last 3 years
No release in over 3 years
Save and manipulate saved params on per-controller basis
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 0
 Project Readme

Gem Version

Params2session

Why

  • To simplify common patterns, related to saving session variables.
  • To store variables in "per-controller scope". For example, in UsersController, calling session_save(:mode) will save params[:mode] to session['users.mode']

Installation

Add this line to your application's Gemfile:

gem 'params2session'

Then execute:

bundle

Usage

This gem can be used in two or more steps:

  • Save variable from params to session
  • (optional) Set default value
  • Get variable from session

Examples:

In controller:

session_save :mode
do_some_stuff if session_param(:mode)

Or:

session_save :mode
session_default :mode, 'all'
do_some_stuff if session_equal?(:mode, 'none')

Or:

session_save :mode
session_update(:mode, 'all') if session_param(':mode') == 'none'
do_some_stuff if session_equal(:mode, 'some')

View layer

session_param and session_equal? helpers are also available in views.

session_equial?(param_name, value) can be used in views to set class on buttons or button groups depending on saved param state, or to render different partial based on saved param.

License

This project rocks and uses MIT-LICENSE.