Giter Club home page Giter Club logo

backable's Introduction

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.

controller

class FooBarsController < ApplicationController

  def index
    backable_push([:foo_bars])			#< push the back-url. This can be a string url
    ..
  end

  def update
    @foo_bar = FooBar.find(params[:id])
    if @foo_bar.update(params[:foo_bar])
      redirect_to backable_back_path, notice: "Data is saved"
    end
  end

end

Available controller methods:

Method description
backable_push Pushes the given url to the stack
backable_url_for url_for replacement which includes the 'back' parameter
backable_back_path Returns the path to the previous page
backable_param Returns the back parameter for the given stack (internal method)
backable_history Returns and array of the previous paths
backable_future Returns 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:

Method description
backable_url_for url_for replacement which includes the 'back' parameter
backable_back_path Returns the path to the previous page
backable_form_item A hidden form element that includes the 'back' parameter
backable_link_to link_to replacement which includes the 'back' parameter
backable_link_to_back A link_to call to the previous page (including the text t(backable.back))
backable_history Returns and array of the previous paths
backable_future Returns 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.

backable's People

Contributors

gamecreature avatar rodoneill avatar

Watchers

 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.