Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

8 Commits

Repository files navigation

Backable

A little gem for supporting back history in your applicaton. It uses a simple request-parameter 'back' with every back-path separated with a '|'.

Installation

Add this line to your application's Gemfile:

gem'backable'

And then execute:

$ bundle

Usage

To use this plugin. You can build up the backable stack via the controller method backable_push. To pass the history to the next page remember to use backable_url_for instead of url_for.

You can configure the Backable.fallback_url, which is called when nothing is on the stack.

Backable.fallback_url

controller

classFooBarsController < ApplicationControllerdefindexbackable_push([:foo_bars])#< push the back-url. This can be a string url
..
enddefupdate@foo_bar=FooBar.find(params[:id])if@foo_bar.update(params[:foo_bar])redirect_tobackable_back_path,notice: "Data is saved"endendend

Available controller methods:

Methoddescription
backable_pushPushes the given url to the stack
backable_url_forurl_for replacement which includes the 'back' parameter
backable_back_pathReturns the path to the previous page
backable_paramReturns the back parameter for the given stack (internal method)
backable_historyReturns and array of the previous paths
backable_futureReturns the future paths (pushed on the stack in this request)

views

To make this all work you need to replace all links in your application (link_to) to backable_link_to

<%= backable_link_to( [:edit, @item]) %>

To use this with buttons etc.. there's also the backable_url_for method

You can simple add a back-button via backable_link_to_back. This link goes back to previous page in the stack.

<%= backable_link_to_back %>

To remember your back-stack in forms you should use the backable_form_item

<%= backable_form_item %>

Available view-helper methods:

Methoddescription
backable_url_forurl_for replacement which includes the 'back' parameter
backable_back_pathReturns the path to the previous page
backable_form_itemA hidden form element that includes the 'back' parameter
backable_link_tolink_to replacement which includes the 'back' parameter
backable_link_to_backA link_to call to the previous page (including the text t(backable.back))
backable_historyReturns and array of the previous paths
backable_futureReturns the future paths (pushed on the stack in this request)

License

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

About

Simple back button support for rails via a back-stack in a request parameter

Resources

Stars

5 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages