/awesome_back_url

Redirect the user to the proper "back" page

Primary LanguageRubyMIT LicenseMIT

awesome_back_url

RailsJazz https://www.patreon.com/igorkasyanchuk Listed on OpenSource-Heroes.com

Redirect to proper back URL for your Rails applications. In case if you want to redirect user not to "edit" or "new" page from "show" after creation, but to "index" or other specific URL.

Usage

Options:

awesome_back_path(path = request.referrer, only: nil, except: nil, fallback: :back)
  • "path" - destination to redirect user
  • "only" - regexp of allowed paths
  • "except" - regexp of disallowed paths
  • "fallback" - if path is incorrect (not allowed or not in allowed) redirect to this url.

Samples:

link_to 'Back', awesome_back_path(except: /\/new|\/edit/, fallback: users_path) # returns '/users'
link_to 'Back', awesome_back_path('/path', except: /\/new/, fallback: '/users') # returns  '/path'
link_to 'Back', awesome_back_path('/path/new', except: /\/new|\/edit/, fallback: '/users') # returns '/users'
link_to 'Back', awesome_back_path('/path/edit', except: /\/new|\/edit/, fallback: '/users') # returns '/users'
link_to 'Back', awesome_back_path('/path', only: /\/new|\/edit/, fallback: '/users') # returns '/users'
link_to 'Back', awesome_back_url('/path', fallback: '/users') # returns '/path'    

Installation

Add this line to your application's Gemfile:

gem 'awesome_back_url'

And then execute:

$ bundle

Contributing

You are welcome to contribute.

License

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