redirect_on_back 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +29 -7
- data/lib/assets/javascripts/redirect_on_back.js +25 -4
- data/lib/redirect_on_back/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MmQwMzBhNmExOWIwNDIwNDE5ZDI2ODhjMDQ4Mjg5NDM1MjRiOTBkOQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NjI4ZDBmYjI3NThmN2FlNDBjY2FmZWZhMTQyNmRmYjM3NTlkYmJiMg==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZDljZWM1M2Q1ZjlkNjI5ODM0NThiNmIzOTIwMmI5NmVlYzcyNzUyMzljNTgz
|
10
|
+
MTVjMjJjZWI4ODExMjkyNGYwMTI0ZWRkOTlmNDQzZWVjZTExNzNiZWY4M2Uw
|
11
|
+
OWFhNTdmY2ZkY2QzZWY5N2QyNzcwZDI3ZDVhZThhNmMwMTY0Njk=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YmZjYTUyNzk1ZWI5ZjliNzJkMzM1NGZjM2E5ODI3YmY5ODUxZTQwYTllMTA4
|
14
|
+
MTZkMmE5MDE5NGM5M2MwNTlhZTA3NmZmZjBlZmI1ODRlNGRmYmFiNWNiODhl
|
15
|
+
NDM5ZGEzYTU3NDMzZTc3ZjdjMzgyODVhMjg5ZjUzM2IxYjI3ODU=
|
data/README.md
CHANGED
@@ -1,24 +1,46 @@
|
|
1
|
-
#
|
1
|
+
# Redirect on Back
|
2
2
|
|
3
|
-
|
3
|
+
Prevent re-submission of a form by redirecting after user hits the back button. For Rails 3.1 and above.
|
4
4
|
|
5
|
-
|
5
|
+
### Example Scenario - User Registration
|
6
|
+
|
7
|
+
1. User registers by filling in form and hits 'submit'.
|
8
|
+
2. User wants to change one of his details.
|
9
|
+
3. User hits 'back'.
|
10
|
+
4. User changes something and hits 'submit' again.
|
11
|
+
5. Arrrggg... a new User record has been created instead of updating the existing one.
|
12
|
+
|
13
|
+
## Installation (Rails 3.1 and higher)
|
6
14
|
|
7
15
|
Add this line to your application's Gemfile:
|
8
16
|
|
9
17
|
gem 'redirect_on_back'
|
10
18
|
|
11
|
-
|
19
|
+
Then execute:
|
12
20
|
|
13
21
|
$ bundle
|
14
22
|
|
15
|
-
Or install it yourself as:
|
16
23
|
|
17
|
-
|
24
|
+
And then specify the use of the redirect_on_back
|
25
|
+
javascripts in your `application.js`:
|
26
|
+
|
27
|
+
//= require redirect_on_back
|
18
28
|
|
19
29
|
## Usage
|
20
30
|
|
21
|
-
|
31
|
+
In your `create` controller actions:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
def create
|
35
|
+
@user = User.build
|
36
|
+
if result = @user.save
|
37
|
+
redirect_on_back edit_user_path(@user) # If user hits 'back' he'll be redirected to edit_user_path
|
38
|
+
redirect_to @user
|
39
|
+
else
|
40
|
+
render :action => :new
|
41
|
+
end
|
42
|
+
end
|
43
|
+
```
|
22
44
|
|
23
45
|
## Contributing
|
24
46
|
|
@@ -1,9 +1,30 @@
|
|
1
|
-
$(function() {
|
2
|
-
|
1
|
+
$(function () {
|
2
|
+
|
3
|
+
function getCookie(c_name) {
|
4
|
+
var c_value = document.cookie;
|
5
|
+
var c_start = c_value.indexOf(" " + c_name + "=");
|
6
|
+
if (c_start == -1) {
|
7
|
+
c_start = c_value.indexOf(c_name + "=");
|
8
|
+
}
|
9
|
+
if (c_start == -1) {
|
10
|
+
c_value = null;
|
11
|
+
}
|
12
|
+
else {
|
13
|
+
c_start = c_value.indexOf("=", c_start) + 1;
|
14
|
+
var c_end = c_value.indexOf(";", c_start);
|
15
|
+
if (c_end == -1) {
|
16
|
+
c_end = c_value.length;
|
17
|
+
}
|
18
|
+
c_value = unescape(c_value.substring(c_start, c_end));
|
19
|
+
}
|
20
|
+
return c_value;
|
21
|
+
}
|
22
|
+
|
23
|
+
return $('input[name=_usec]').each(function () {
|
3
24
|
var redirect_path, token;
|
4
25
|
if (token = $(this).val()) {
|
5
|
-
redirect_path =
|
6
|
-
if (redirect_path) {
|
26
|
+
redirect_path = getCookie("redirect_" + token);
|
27
|
+
if (redirect_path && redirect_path.length) {
|
7
28
|
$('body').hide();
|
8
29
|
return window.location.href = redirect_path;
|
9
30
|
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redirect_on_back
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yossi-shasho
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|