Code Monkey home page Code Monkey logo

remember_params's Introduction

RememberParams

Rails gem that makes actions remember GET params like keywords and page.

Scenario

Say you have that index action where you can search, filter and paginate through records. Once you click on one of the records you lose track of the exact location (e.g. search keywords, filter settings or page).

RememberParams will bring users back to that exact location when they return to the index page by remembering the search keywords, filter settings and page.

Usage

To make a controller action remember its params simply add the remember_params line on top like this:

class BooksController < ApplicationController
  remember_params :keywords, :page # defaults are on: index and duration: 1.hour
  remember_params :client_id, on: :client_list, duration: 1.minute
end

Browsing the action without any params will automatically try to restore params and redirect to the same route but with previously set params.

If for example you have the keywords params remembered and follow a link with only a page param, the remembered keywords param and the newly set page param will be mixed.

Reset all remembered params like this:

link_to 'Books', books_path(reset_params: true)

You can also mix reset_params and setting new params.

link_to 'Books', books_path(reset_params: true, page: 2)

Installation

Add this line to your application's Gemfile:

gem 'remember_params'

And then execute:

$ bundle

Or install it yourself as:

$ gem install remember_params

License

The gem is available as open source under the terms of the MIT License.

remember_params's People

Contributors

jtreitz avatar aliismayilov avatar pheisiph avatar

Stargazers

Claudemiro A F Neto avatar

Watchers

Josh Garth avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.