Plugins - History

StarAdd to favorites

History

This plugins stores the history of locations visited by a user. I felt annoyed enough when having to redirect user back to their previous location in a hackish way that I wrote this plugin.

It avoids storing POST,PUT, DELETE and Ajax request. It also has a facility to specify actions not to store in the history.

1. Installation

Unpack into the vendor/plugin and that should be it.

2. Usage

In your app/controllers/application_controller.rb, add a history line like this:

  class ApplicationController < ActionController::Base
    history :default => "http://default.url.com/", :max => 10
  end

The history function accepts a hash of options

  • :default, the default URL to redirect
  • :max, the maximum locations to remember (five by defaults).

None of the parameters are required. If somebody know of a better way to obtain the default URL, he is welcomed to tell me how.

You can use the method history_skip in your controller if you want to avoid certain location to be stored in the history. By default, action resulting from a POST, PUT, DELETE request or an Ajax request are not stored in the history.

  class FooController < ApplicationController
    history_skip :action_to_skip

    def action_to_skip
      # I will not be stored in the history
    end
  end

In your actions, you can then use the following methods:

  • last_location: returns the last visited location, can be used with one numeric argument precising how many locations to go back in the history (1 by default),
  • peek_last_location: like last_location but don’t remove it from the history,
  • redirect_back: redirect the user to the last location in history, it takes the same arguments as last_location,
  • store_location(force = false): stores the current location in the history, set force parameter to true to store location even if it would be skipped.

3. License

This plugin is licensed under the MIT license.

4. Author

This plugin was created by Damien Merenne and is located at http://blog.cosinux.org/pages/rails-history.

Damien Merenne

http://blog.cosinux.org/pages/rails-history

Rails' (MIT)

  • Currently 2.8/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Controllers

Tags

Comments

Add a comment

Search Plugins

Query syntax

Plugins by Category

Sponsors

Rails Kits: Get Code. Get Moving.

Have a comment?