https://github.com/elmassimo/rails-ajax_redirect
↩️ Provides redirect support for ajax requests in Rails
https://github.com/elmassimo/rails-ajax_redirect
ajax-request rails redirects turbolinks
Last synced: 2 months ago
JSON representation
↩️ Provides redirect support for ajax requests in Rails
- Host: GitHub
- URL: https://github.com/elmassimo/rails-ajax_redirect
- Owner: ElMassimo
- License: mit
- Created: 2015-12-29T21:09:21.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-12-29T21:47:59.000Z (over 10 years ago)
- Last Synced: 2025-03-27T08:59:22.159Z (over 1 year ago)
- Topics: ajax-request, rails, redirects, turbolinks
- Language: Ruby
- Homepage: https://maximomussini.com/posts/rails-ajax_redirect/
- Size: 7.81 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
Rails::AjaxRedirect
=====================
[](http://badge.fury.io/rb/rails-ajax_redirect)
[](https://github.com/ElMassimo/rails-ajax_redirect/blob/master/LICENSE.txt)
Simple `redirect_to` support for AJAX requests in non-Turbolinks applications.
## Installation
Add this line to your application's Gemfile:
gem 'rails-ajax_redirect'
Or install it yourself as:
gem install rails-ajax_redirect
## Usage
Require `rails-ajax_redirect` in your `application.js`:
``` javascript
//= require rails-ajax_redirect
```
`AjaxRedirect` extends `redirect_to` to use a custom status code for ajax
requests, while still setting the `Location` header.
The script adds a handler for the `ajax:success` event, that navigates to the
location in the header for responses that have the custom status code.
Now you will be able to write controller actions in the usual way :smiley:
## Turbolinks
If your application uses Turbolinks check out [`turbolinks-redirect`](https://github.com/remind101/turbolinks-redirect), on which this library is based on. The advantage is that
it will perform faster navigation by leveraging Turbolinks to visit the new
location.
License
--------
Copyright (c) 2015 Máximo Mussini
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.