0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Improved redirect back in rails
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

~> 5.1.6
 Project Readme

BackFormer

Improved redirect back in rails.

In Rails 5, we have new method #redirect_back, but this method is feature which seeing referer only. This may be lack of function.
Example, please imagine when you implement controller they have to login.
You should redirect from login needed controller to new action ( GET /login form, input) and then redirect to create action ( POST /login evaluate),
but when user has moved from new to create, referer is expectly overriding GET /login and you can't redirect back to login needed controller with #redirect_back.

This gem provide feature which store previous url, redirect stored url and skip storing url. they makes it possible to redirect after logging in.

Installation

Add this line to your application's Gemfile:

gem 'back_former'

And then execute:

$ bundle

Or install it yourself as:

$ gem install back_former

Usage

class ApplicationController
  before_action :save_previous_path  # save current page path to your session
end

class LoginNeededController
  before_action -> {
    redirect_to login_path unless logged_in?
  }
  def index; end
end

class LoginController
  skip_before_action :save_previous_path
  def new; end

  def create
    redirect_back_former
  end
end
  1. Access to /login_needed/ then redirect /login
  2. Post request to /login (create)
  3. redirect to /login_needed/

Contributing

Contribution directions go here.

License

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